-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Netzvamp/main
Event body handling
- Loading branch information
Showing
6 changed files
with
159 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,77 @@ | ||
import logging | ||
|
||
import os | ||
from rich.logging import RichHandler | ||
|
||
logger = logging.getLogger(__name__) | ||
# Define TRACE level | ||
TRACE_LEVEL_NUM = 5 | ||
logging.addLevelName(TRACE_LEVEL_NUM, "TRACE") | ||
|
||
|
||
def trace(self, message, *args, **kws): | ||
if self.isEnabledFor(TRACE_LEVEL_NUM): | ||
self._log(TRACE_LEVEL_NUM, message, args, **kws) | ||
|
||
|
||
logging.Logger.trace = trace | ||
|
||
|
||
def get_log_level() -> int: | ||
""" | ||
Get log level from environment variable or return default (INFO). | ||
Valid values for LOG_LEVEL are: DEBUG, INFO, WARNING, ERROR, CRITICAL, TRACE | ||
Returns logging level constant. | ||
""" | ||
level_map = { | ||
'TRACE': TRACE_LEVEL_NUM, | ||
'DEBUG': logging.DEBUG, | ||
'INFO': logging.INFO, | ||
'WARNING': logging.WARNING, | ||
'ERROR': logging.ERROR, | ||
'CRITICAL': logging.CRITICAL | ||
} | ||
|
||
env_level = os.getenv('GENESIS_LOG_LEVEL', 'INFO').upper() | ||
return level_map.get(env_level, logging.INFO) | ||
|
||
|
||
def setup_logger(name: str = __name__) -> logging.Logger: | ||
"""Configure a logger with rich handler and conventional formatting. | ||
Args: | ||
name: The name for the logger instance | ||
Returns: | ||
A configured logger instance | ||
""" | ||
logger = logging.getLogger(name) | ||
|
||
# Prevent duplicate handlers | ||
if logger.handlers: | ||
return logger | ||
|
||
# Configure Rich Handler according to conventions | ||
handler = RichHandler( | ||
rich_tracebacks=True, | ||
tracebacks_show_locals=True, | ||
markup=True, | ||
show_path=False, | ||
show_time=True, | ||
omit_repeated_times=False | ||
) | ||
|
||
formatter = logging.Formatter("%(message)s") | ||
handler.setFormatter(formatter) | ||
|
||
# Get log level from environment variable | ||
log_level = get_log_level() | ||
logger.setLevel(log_level) | ||
logger.addHandler(handler) | ||
logger.propagate = False | ||
|
||
handler = RichHandler( | ||
show_time=False, | ||
rich_tracebacks=True, | ||
tracebacks_show_locals=True, | ||
markup=True, | ||
show_path=False, | ||
) | ||
logger.debug(f"Logger initialized with level: {logging.getLevelName(log_level)}") | ||
return logger | ||
|
||
handler.setFormatter(logging.Formatter("%(message)s")) | ||
|
||
logger.setLevel(logging.INFO) | ||
logger.addHandler(handler) | ||
logger.propagate = False | ||
# Create default logger | ||
logger = setup_logger(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters