- Notifications
You must be signed in to change notification settings - Fork 63
add structure file logging with log files rotating #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| | @@ -11,27 +11,63 @@ | |||||||||||||||||||||||||
| from app.utils.singleton import SingletonMetaNoArgs | ||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||
| # TODO: merge this wrapper with the one in structlog under one hood of AppLogger | ||||||||||||||||||||||||||
| class BytesToTextIOWrapper: | ||||||||||||||||||||||||||
| def __init__(self, handler, encoding="utf-8"): | ||||||||||||||||||||||||||
| class RotatingBytesLogger: | ||||||||||||||||||||||||||
| """Logger that respects RotatingFileHandler's rotation capabilities.""" | ||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||
| def __init__(self, handler): | ||||||||||||||||||||||||||
| self.handler = handler | ||||||||||||||||||||||||||
| self.encoding = encoding | ||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||
| def write(self, b): | ||||||||||||||||||||||||||
| if isinstance(b, bytes): | ||||||||||||||||||||||||||
| self.handler.stream.write(b.decode(self.encoding)) | ||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||
| self.handler.stream.write(b) | ||||||||||||||||||||||||||
| self.handler.flush() | ||||||||||||||||||||||||||
| def msg(self, message): | ||||||||||||||||||||||||||
| """Process a message and pass it through the handler's emit method.""" | ||||||||||||||||||||||||||
| if isinstance(message, bytes): | ||||||||||||||||||||||||||
| message = message.decode("utf-8") | ||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||
| # Create a log record that will trigger rotation checks | ||||||||||||||||||||||||||
| record = logging.LogRecord( | ||||||||||||||||||||||||||
| name="structlog", | ||||||||||||||||||||||||||
| level=logging.INFO, | ||||||||||||||||||||||||||
| pathname="", | ||||||||||||||||||||||||||
| lineno=0, | ||||||||||||||||||||||||||
| Comment on lines +26 to +30 | ||||||||||||||||||||||||||
| record = logging.LogRecord( | |
| name="structlog", | |
| level=logging.INFO, | |
| pathname="", | |
| lineno=0, | |
| import inspect | |
| frame = inspect.stack()[1] | |
| record = logging.LogRecord( | |
| name="structlog", | |
| level=logging.INFO, | |
| pathname=frame.filename, | |
| lineno=frame.lineno, |
Copilot AI Jul 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All logging level methods (debug, info, warning, error, critical) delegate to the same msg() method with INFO level. This means debug messages will be logged at INFO level, which could lead to incorrect log filtering and analysis.
Copilot AI Jul 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The slots=True parameter was removed from the @define decorator. This change reduces memory efficiency and performance for the AppStructLogger class instances. Consider keeping slots=True unless there's a specific reason to remove it.
| @define | |
| @define(slots=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slots are true by default
Copilot AI Jul 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The slots=True parameter was removed from the @define decorator. This could impact memory efficiency and attribute access performance for the singleton class. Consider adding it back unless there's a specific reason for removal.
| @define | |
| @define(slots=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The async logger methods like
ainfodo not appear to be defined in theRotatingBytesLoggerclass. Only synchronous methods (debug, info, warning, error, critical) are implemented, so this call will likely result in an AttributeError.