Skip to content

Commit

Permalink
[2051] Logging File Check
Browse files Browse the repository at this point in the history
  • Loading branch information
Rixxan committed Nov 17, 2023
1 parent 960b00e commit 95c7317
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions EDMCLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# See, plug.py:load_plugins()
logger = logging.getLogger(f'{appname}.{plugin_name}')
"""
from __future__ import annotations

import inspect
import logging
Expand All @@ -48,7 +49,7 @@
from threading import get_native_id as thread_native_id
from time import gmtime
from traceback import print_exc
from typing import TYPE_CHECKING, Tuple, cast
from typing import TYPE_CHECKING, cast

import config as config_mod
from config import appcmdname, appname, config
Expand Down Expand Up @@ -122,15 +123,13 @@ class LoggerMixin(logging.Logger):

def trace(self, message, *args, **kwargs) -> None:
"""See implementation above."""
...

def trace_if(self, condition: str, message, *args, **kwargs) -> None:
"""
Fake trace if method, traces only if condition exists in trace_on.
See implementation above.
"""
...


class Logger:
Expand Down Expand Up @@ -183,18 +182,12 @@ def __init__(self, logger_name: str, loglevel: int | str = _default_loglevel):
# rotated versions.
# This is {logger_name} so that EDMC.py logs to a different file.
logfile_rotating = pathlib.Path(tempfile.gettempdir())
logfile_rotating = logfile_rotating / f'{appname}'
logfile_rotating /= f'{appname}'
logfile_rotating.mkdir(exist_ok=True)
logfile_rotating = logfile_rotating / f'{logger_name}-debug.log'

self.logger_channel_rotating = logging.handlers.RotatingFileHandler(
logfile_rotating,
mode='a',
maxBytes=1024 * 1024, # 1MiB
backupCount=10,
encoding='utf-8',
delay=False
)
logfile_rotating /= f'{logger_name}-debug.log'

self.logger_channel_rotating = logging.handlers.RotatingFileHandler(logfile_rotating, maxBytes=1024 * 1024,
backupCount=10, encoding='utf-8')
# Yes, we always want these rotated files to be at TRACE level
self.logger_channel_rotating.setLevel(logging.TRACE) # type: ignore
self.logger_channel_rotating.setFormatter(self.logger_formatter)
Expand Down Expand Up @@ -325,7 +318,7 @@ def filter(self, record: logging.LogRecord) -> bool:
return True

@classmethod
def caller_attributes(cls, module_name: str = '') -> Tuple[str, str, str]: # noqa: CCR001, E501, C901 # this is as refactored as is sensible
def caller_attributes(cls, module_name: str = '') -> tuple[str, str, str]: # noqa: CCR001, E501, C901 # this is as refactored as is sensible
"""
Determine extra or changed fields for the caller.
Expand Down Expand Up @@ -535,9 +528,8 @@ def get_main_logger(sublogger_name: str = '') -> 'LoggerMixin':
if not os.getenv("EDMC_NO_UI"):
# GUI app being run
return cast('LoggerMixin', logging.getLogger(appname))
else:
# Must be the CLI
return cast('LoggerMixin', logging.getLogger(appcmdname))
# Must be the CLI
return cast('LoggerMixin', logging.getLogger(appcmdname))


# Singleton
Expand Down

0 comments on commit 95c7317

Please sign in to comment.