tags: #public
- Logging is configured as part of the general Django setup() function.
- There are mainly 4 components
- Logger
- Handles only messages that are greater than equal to it’s log level
- There are 5 log levels in Python
- DEBUG
- INFO
- WARNING
- ERROR
- CRITICAL
- Can have multiple handlers for one logger
- The name is usually
__name__
.
logger = logging.getLogger('project.interesting.stuff')
project.interesting
is a parent of project.interesting.stuff
project
is a parent of `project.interesting
- So you can define handlers for child loggers in parent level.
- Defining a logger on
project
will capture the logging calls in project.interesting
and project.interesting.stuff
- There is option to turn this off as well.
- Handlers
- Handlers decide what to do with the mesage
- eg ; write message to screen, file, socket etc
- Handlers also have log levels. So the message should atleast have the log level of the handler.
- Filters
- Provides additional control on what messages are passed from logger to handlers.
- Can update the log level of the message if necessary/
- Can be installed on loggers or handlers
- Formatters
- Every record is rendered at text at the end.
- Formatter describes the exact format of the text.