Giter Site home page Giter Site logo

python_logging's Introduction

[Hierarchy] Specify your base logger name in documentation when using __name__ as logger name.

  1. logging_example.py
  2. root_logger_issue/main.py
  3. multiple_loggers/main.py
  4. log_exception_stacktrace/main.py
  5. handlers/*.py
  6. custom_formatter.py
  7. hierarchy/main.py
  8. filters.py
  9. logging_config/main.py

Logger

Receives log messages

  • level
  • propagate
  • filters
  • handlers

LogRecord

Contain information about the function, file name, full path where the log was requested, the string that was passed, arguments, call stack information, etc. These are the objects that are being logged. Every time we invoke our loggers, we are creating instances of these objects.

  • Created automatically by the logger every time something is logged
  • Can be created manually via logging.makeLogRecord

Handlers

https://docs.python.org/2/library/logging.handlers.html#module-logging.handlers

Handlers emit the log records into any output. They take log records and handle them in the function of what they were built for. As an example, a FileHandler will take a log record and append it to a file.

The handler will then use a Formatter to turn the LogRecord into a string and emit that string.

  • class
  • level
  • filters
  • formatter

Formatter

Format a log record for output. Formatters are in charge of serializing the metadata-rich LogRecord into a string. There is a default formatter if none is provided.

  • format
  • date format
  • style (%,{,$)

Filters

Control which LogRecord should be emitted

  1. from Logger ---> Handlers [Filter at logger level]
  2. from Handlers ---> Formatter [Filter at Handler level]

Users can declare their own filters as objects using a filter method that takes a record as input and returns True/False as output.

References

python_logging's People

Contributors

gravi80 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.