Python Logging Basics

python_tutorials

Introduction

Logging helps you keep track of events happening during the execution of your code, which can then be used in the future for debugging purposes. It provides a better picture of the flow of the application and helps developers trace the source of errors that happens during execution of your code, thereby enhancing the maintainability of the application.

In Python, most of the basic logging features are provided by the Python standard library. Hence, you can add logging to your application easily without any extra configurations. The standard logging module enables the developer to write status messages to a file or any other output stream.

The logging Module

The logging module is readily available in Python environments by default and provides a default logger named “root”. It defines the functions and classes that implement logging functionality.

The logging API provided by the standard library enables you to include your own messages in the application log, as well as integration with messages from third-party modules. It also provides a mechanism to annotate the log messages with the source, timestamp, severity and other metadata, which helps in log analysis.

Logging Types (Log levels)

Each log message is

To finish reading, please visit source site