-
Notifications
You must be signed in to change notification settings - Fork 2
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 #39 from SwiftSeal/logging
Update logging system
- Loading branch information
Showing
11 changed files
with
306 additions
and
398 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
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 +1 @@ | ||
__version__ = "1.0.1" | ||
__version__ = "1.1.0" |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import sys | ||
from loguru import logger as _logger | ||
|
||
|
||
class LoggerDelegator: | ||
def __init__(self, logger): | ||
self._logger = logger | ||
self._configure_logger() | ||
|
||
def _configure_logger(self): | ||
# Remove default handler | ||
self._logger.remove() | ||
|
||
# Add a new handler with a default format and dynamic level | ||
log_level = os.getenv("LOG_LEVEL", "INFO") | ||
self._logger.add( | ||
sink=sys.stdout, | ||
format="[{time:HH:mm:ss}] <level>{level: <8}</level> {message}", | ||
level=log_level, | ||
) | ||
|
||
def update_level(self, level): | ||
os.environ["LOG_LEVEL"] = level # Set globally for spawned processes | ||
self._configure_logger() # Reconfigure logger in the main process | ||
|
||
def __getattr__(self, attr): | ||
return getattr(self._logger, attr) | ||
|
||
|
||
logger = LoggerDelegator(_logger) |
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
Oops, something went wrong.