Skip to main content

Make logging simple, log even uncaught exception

Project description

Logger_tt

Make configuring logging simpler and log even exceptions that you forgot to catch.

Usage:

Install: pip install logger_tt

In the most simple case, add the following code into your main python script of your project:

from logger_tt import setup_logging    

setup_logging()

Then from any of your modules, you just need to get a logger and start logging.

from logging import getLogger

logger = getLogger(__name__)

logger.debug('Module is initialized')
logger.info('Making connection ...')

This will provide your project the following default log behavior:

  • log file: Assume that your working directory is project_root, log.txt is stored at your project_root/logs/ folder. If log path doesn't exist, it will be created. The log file is time rotated at midnight. Maximum of 15 dates of log will be kept. This log file's level is DEBUG.
    The log format is [%(asctime)s] [%(name)s %(levelname)s] %(message)s where time is %Y-%m-%d %H:%M:%S.
    Example: [2020-05-09 00:31:33] [myproject.mymodule DEBUG] Module is initialized

  • console: log with level INFO and above will be printed to stdout of console. The format for console log is simpler: [%(asctime)s] %(levelname)s: %(message)s.
    Example: [2020-05-09 00:31:34] INFO: Making connection ...

  • urllib3 logger: this ready made logger is to silent unwanted messages from requests library.

  • root logger: if there is no logger initialized in your module, this logger will be used with above behaviors. This logger is also used to log uncaught exception in your project. Example:

raise RecursionError
# log.txt
[2020-05-09 11:42:08] [root ERROR] Uncaught exception
Traceback (most recent call last):
  File "D:/MyProject/Echelon/eyes.py", line 13, in <module>
    raise RecursionError
RecursionError

Config:

  1. You can overwrite the default log path with your own as following:

    setup_logging(log_path='new/path/to/your_log.txt')

  2. You can config your own logger and handler by providing either yaml or json config file as following:

    setup_logging(config_path='path/to/.yaml_or_.json')

    Without providing a config file, the default config file with above default log behavior is used. You could copy log_conf.yaml or log_conf.json shipped with this package to start making your version.

Warning: To process .yaml config file, you need to pyyaml package: pip install pyyaml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logger_tt-1.0.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logger_tt-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file logger_tt-1.0.0.tar.gz.

File metadata

  • Download URL: logger_tt-1.0.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4

File hashes

Hashes for logger_tt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 061ef1f81a05eafb9880b1412c340690f520bcef2bd3e1540c86a1770c6f3b80
MD5 45a202402223c5b085277f745179458d
BLAKE2b-256 c6ff88baaf1934fc2fc1a0f26879b5e646442f34abfaa143a9a2ec50f53d090d

See more details on using hashes here.

File details

Details for the file logger_tt-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: logger_tt-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4

File hashes

Hashes for logger_tt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31308860d4e5a2526839b8fd90323fd2b05b28dde2bb44f30b09a0763243c89a
MD5 03aceeb635ff35046bbefddb201aba06
BLAKE2b-256 d9a40954f3cd66a895030a531efe7ecd088102a716a6f9e3f30595891d57aa33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page