Skip to main content

Hierarchical logging in yaml format

Project description

Hierarchical logging in yaml format.

Hierarchical logging help to group logs that are related to the same code flow.

Log style can be styled in Yaml format or in Line format.

Examples:

Output in YAML style

from examples.demo_classes.demo_classes import NAME_1, A
from nrt_logging.logger_manager import logger_manager
from nrt_logging.logger_stream_handlers import \
    ConsoleStreamHandler, LogStyleEnum


def logging_line_style():
    sh = ConsoleStreamHandler()
    sh.style = LogStyleEnum.LINE
    logger = logger_manager.get_logger(NAME_1)
    logger.add_stream_handler(sh)
    a = A()
    a.a1()


def logging_yaml_style():
    sh = ConsoleStreamHandler()
    sh.style = LogStyleEnum.YAML
    logger = logger_manager.get_logger(NAME_1)
    logger.add_stream_handler(sh)
    a = A()
    a.a1()


logging_yaml_style()

Output

---
date: 2022-10-21 21:20:49.658272
log_level: WARN
path: demo_classes.py.A
method: a1
line_number: 32
message: Message 1
children:
  - date: 2022-10-21 21:20:49.666366
    log_level: INFO
    path: demo_classes.py.Child
    method: child_1
    line_number: 16
    message: Child 1
    children:
      - date: 2022-10-21 21:20:49.675316
        log_level: INFO
        path: demo_classes.py.Child
        method: child_2
        line_number: 20
        message: Child 2

Output in LINE style

from nrt_logging.log_level import LogLevelEnum
from nrt_logging.logger_manager import logger_manager
from nrt_logging.logger_stream_handlers import \
    ConsoleStreamHandler, LogStyleEnum


sh = ConsoleStreamHandler()
sh.log_level = LogLevelEnum.TRACE
sh.style = LogStyleEnum.LINE
logger = logger_manager.get_logger('NAME_1')
logger.add_stream_handler(sh)

logger.info('main level log')
logger.increase_depth()
logger.info('child 1')
logger.increase_depth()
logger.info('child 1_1')
logger.decrease_depth()
logger.info('child 2')
logger.decrease_depth()
logger.info('continue main level')

Output

- log: 2022-10-21 21:30:16.361425 [INFO] [manual_hierarchy_line_logging.py.<module>:13] main level log
  children:
    - log: 2022-10-21 21:30:16.367386 [INFO] [manual_hierarchy_line_logging.py.<module>:15] child 1
      children:
        - log: 2022-10-21 21:30:16.373975 [INFO] [manual_hierarchy_line_logging.py.<module>:17] child 1_1
    - log: 2022-10-21 21:30:16.380979 [INFO] [manual_hierarchy_line_logging.py.<module>:19] child 2
- log: 2022-10-21 21:30:16.387013 [INFO] [manual_hierarchy_line_logging.py.<module>:21] continue main level

Config file

log_manager config file in YAML style.
Configure loggers and stream handlers.

parameters are inherited. Parameters that are deeper in YAML file will be taken.

log_level: WARN
date_format: '%Y-%m-%d %H:%M:%S'
loggers:
  - name: TEST1
    style: yaml
    log_line_template: '[$log_level$] <$date$> $message$'
    stream_handlers:
      - type: console
        style: line
      - type: file
        file_path: logs/log_test_1.txt
        log_level: DEBUG
        style: line
        date_format: '%Y'
        log_line_template: 'Test1 $date$ $message$'
  - name: TEST2
    style: yaml
    stream_handlers:
      - type: file
        file_path: logs/log_test_2.txt
        log_level: ERROR
        date_format: '%Y'
        log_yaml_elements:
          ['log_level', 'date', 'message']
from examples.demo_classes.demo_classes import \
    NAME_1, A, NAME_2
from nrt_logging.logger_manager import logger_manager
from nrt_logging.logger_stream_handlers import ManualDepthEnum

CONFIG_FILE_PATH = './config/config1.yaml'

logger_manager.set_config(file_path=CONFIG_FILE_PATH)

Wiki: https://github.com/etuzon/Python-NRT-Logging/wiki/NRT-Logging

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

nrt-logging-1.1.1.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

nrt_logging-1.1.1-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file nrt-logging-1.1.1.tar.gz.

File metadata

  • Download URL: nrt-logging-1.1.1.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for nrt-logging-1.1.1.tar.gz
Algorithm Hash digest
SHA256 50b4026232a7b6898368a684e28f2fd9e4c277b5f022701353a32f98587021eb
MD5 9ac837987b42962728b176baa93fe28a
BLAKE2b-256 deb985d6c7f56b296a1c6732f2df906bee31fbf16553068303a59f0bd64f5989

See more details on using hashes here.

File details

Details for the file nrt_logging-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: nrt_logging-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for nrt_logging-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 120c2748100a4f9d09512e47dc235245064f8729b57cd3a958b2bb4c7d2328ea
MD5 da263a2a66c3a55f57d77d76520484c8
BLAKE2b-256 b40d958c6244bc13fac8b0a0039e3982b5a22a5e183c646c3352c67cbb917817

See more details on using hashes here.

Supported by

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