Skip to content

Commit

Permalink
Add log to file tad.log
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed May 10, 2024
1 parent 41a7956 commit 571164f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ __pypackages__/

# macos
.DS_Store

# tad tool
tad.log*
48 changes: 48 additions & 0 deletions tad/core/log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import copy
import logging
import logging.config
from typing import Any

from tad.core.types import LoggingLevelType

LOGGING_SIZE = 10 * 1024 * 1024
LOGGING_BACKUP_COUNT = 5

LOGGING_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"generic": {
"()": "logging.Formatter",
"style": "{",
"fmt": "{asctime}({levelname},{name}): {message}",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
}
},
"handlers": {
"console": {"formatter": "generic", "class": "logging.StreamHandler", "stream": "ext://sys.stdout"},
"file": {
"formatter": "generic",
"()": "logging.handlers.RotatingFileHandler",
"filename": "tad.log",
"maxBytes": LOGGING_SIZE,
"backupCount": LOGGING_BACKUP_COUNT,
},
},
"loggers": {
"tad": {"handlers": ["console", "file"], "level": "DEBUG", "propagate": True},
},
}


def configure_logging(level: LoggingLevelType = "INFO", config: dict[str, Any] | None = None) -> None:
log_config = copy.deepcopy(LOGGING_CONFIG)

if config:
log_config.update(config)

logging.config.dictConfig(log_config)

logger = logging.getLogger("tad")

logger.setLevel(level)
9 changes: 0 additions & 9 deletions tad/core/logger.py

This file was deleted.

0 comments on commit 571164f

Please sign in to comment.