Skip to content

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

Merged
merged 4 commits into from
Jul 26, 2025

Conversation

grillazz
Copy link
Owner

No description provided.

@grillazz grillazz requested a review from Copilot July 26, 2025 17:28
Copilot

This comment was marked as outdated.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@grillazz grillazz requested a review from Copilot July 26, 2025 17:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements structured file logging with log file rotation capabilities by refactoring the logging system to use a custom RotatingBytesLogger that properly handles file rotation and converts all logging calls to async operations.

  • Replaces the old BytesToTextIOWrapper with a new RotatingBytesLogger that properly integrates with RotatingFileHandler
  • Updates all logging calls throughout the codebase from synchronous to asynchronous operations (e.g., logger.info() to await logger.ainfo())
  • Removes unnecessary imports and improves log message formatting

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
app/utils/logging.py Implements new rotating logger classes and removes old wrapper implementation
app/services/scheduler.py Converts logging calls to async operations
app/services/auth.py Converts logging calls to async operations
app/models/base.py Converts logging calls to async operations
app/main.py Converts logging calls to async operations
app/database.py Converts logging calls to async operations
app/api/user.py Converts logging calls to async operations
app/api/stuff.py Converts logging calls to async operations and improves log message
app/api/health.py Removes unused import and converts logging calls to async operations



@define(slots=True)
@define
Copy link
Preview

Copilot AI Jul 26, 2025

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.

Suggested change
@define
@define(slots=True)

Copilot uses AI. Check for mistakes.

Comment on lines +45 to +57
self.msg(message)

def info(self, message):
self.msg(message)

def flush(self):
self.handler.flush()
def warning(self, message):
self.msg(message)

def error(self, message):
self.msg(message)

def critical(self, message):
self.msg(message)
Copy link
Preview

Copilot AI Jul 26, 2025

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 uses AI. Check for mistakes.

Comment on lines +26 to +30
record = logging.LogRecord(
name="structlog",
level=logging.INFO,
pathname="",
lineno=0,
Copy link
Preview

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LogRecord is created with hardcoded values for pathname="" and lineno=0. This removes valuable debugging information about where the log message originated from, making troubleshooting more difficult.

Suggested change
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 uses AI. Check for mistakes.

@@ -88,7 +87,7 @@ async def smtp_check(
"subject": subject,
}

logger.info("Sending email with data: %s", email_data)
await logger.ainfo("Sending email.", email_data=email_data)
Copy link
Preview

Copilot AI Jul 26, 2025

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 ainfo do not appear to be defined in the RotatingBytesLogger class. Only synchronous methods (debug, info, warning, error, critical) are implemented, so this call will likely result in an AttributeError.

Suggested change
await logger.ainfo("Sending email.", email_data=email_data)
logger.info("Sending email.", extra={"email_data": email_data})

Copilot uses AI. Check for mistakes.

@grillazz grillazz merged commit 6f82883 into main Jul 26, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant