The record dict stores all contextual information associated with a given log message. They can be contextualised with the record dict. Sinks are responsible for managing log messages. In essence, the add() function is used to register sinks. When using loguru, there is a single function that you will need to know: add().Īs the loguru documentation states: One function to rule them all. If you have ever worked with Python's logging module, you may know that you can use custom handlers, formatters, and filters to personalise the output of the logger. If you are looking for customisation capabilities, follow along and explore loguru's most powerful method.
The default behaviour - importing loguru.logger and using it as an instance of Python's standard library logging.Logger class - is already sufficient for smaller projects and sample code. If you execute the snippet on your local machine, you will also recognise that loguru innately supports coloured log messages. Note, that the file location is _main_ because we executed hello.py directly.įurthermore, the scope is set to as the log message is located in the module's scope and not inside a function or class.