Skip to content

Commit

Permalink
Removed an indentation level.
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaVili committed Nov 21, 2024
1 parent 223e19b commit 681c13e
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,45 +126,43 @@ def get_logger() -> logging.Logger:
# Create console handler with color formatting
console_handler = logging.StreamHandler()
console_handler.setFormatter(ColorFormatter())
handlers: list[logging.Handler] = [console_handler]

settings = get_settings()

# In development, set higher logging level for httpx
if settings.ENVIRONMENT == "development":
logger.setLevel(logging.INFO)
logging.getLogger(name="httpx").setLevel(logging.WARNING)
elif settings.SMTP_HOST is None or settings.SMTP_USER is None or settings.SMTP_PASSWORD is None:
logger.addHandler(console_handler)
return logger
if settings.SMTP_HOST is None or settings.SMTP_USER is None or settings.SMTP_PASSWORD is None:
raise ValueError("All email environment variables are required in production.")
else:
logger.setLevel(logging.ERROR)

# Create file handler with standard formatting
file_handler = RotatingFileHandler(
filename=ROOT_DIR / "export_log.log",
mode="a",
maxBytes=FileHandlerConfig.MAX_BYTES,
backupCount=FileHandlerConfig.BACKUP_COUNT,
encoding="utf-8",
)
file_handler.setFormatter(logging.Formatter(ColorFormatter.BASE_FORMAT))

# Create email handler with standard formatting
email_handler = SMTPHandler(
mailhost=(settings.SMTP_HOST, SMTP_PORT),
fromaddr=settings.SMTP_USER,
toaddrs=settings.SMTP_USER,
subject="Application Error",
credentials=(settings.SMTP_USER, settings.SMTP_PASSWORD.get_secret_value()),
secure=(),
)
email_handler.setFormatter(logging.Formatter(ColorFormatter.BASE_FORMAT))

handlers.extend((file_handler, email_handler))
logger.setLevel(logging.ERROR)

# Create file handler with standard formatting
file_handler = RotatingFileHandler(
filename=ROOT_DIR / "export_log.log",
mode="a",
maxBytes=FileHandlerConfig.MAX_BYTES,
backupCount=FileHandlerConfig.BACKUP_COUNT,
encoding="utf-8",
)
file_handler.setFormatter(logging.Formatter(ColorFormatter.BASE_FORMAT))

# Create email handler with standard formatting
email_handler = SMTPHandler(
mailhost=(settings.SMTP_HOST, SMTP_PORT),
fromaddr=settings.SMTP_USER,
toaddrs=settings.SMTP_USER,
subject="Application Error",
credentials=(settings.SMTP_USER, settings.SMTP_PASSWORD.get_secret_value()),
secure=(),
)
email_handler.setFormatter(logging.Formatter(ColorFormatter.BASE_FORMAT))

# Remove any existing handlers and add new ones
logger.handlers.clear()
for handler in handlers:
for handler in (console_handler, file_handler, email_handler):
logger.addHandler(handler)

return logger
Expand Down

0 comments on commit 681c13e

Please sign in to comment.