Let's study Python

Python logging: a flexible event logging system for all your application needs.

# Python Logging Configuration

## Introduction
In Python, logging is a built-in module that provides a flexible event logging system for applications and libraries. It allows modules to participate in logging, enabling integration of custom messages with standard library messages in application logs.

## Basic Log Output
To get started with logging in Python, the `logging` module needs to be imported. Basic configuration for logging can be set up using the `basicConfig` method. Here is an example:

“`python
import logging
logging.basicConfig(level=logging.DEBUG)
logging.warning(‘Fake Warning.’)
“`

In the above code snippet:
– `import logging`: Imports the logging module.
– `logging.basicConfig(level=logging.DEBUG)`: Sets up basic configuration for logging with a specified logging level.
– `logging.warning(‘Fake Warning.’)`: Logs a warning message.

### Explanation
– `basicConfig`: This method is used for one-time log configuration.
– Official documentation: [logging — Python 3.8.2 Documentation](https://docs.python.org/ko/3.8/library/logging.html#logging.basicConfig)

## Logging Elements
The logging module in Python consists of four main elements:

### 1. Logger
– Responsible for providing the interface for the logging module.
– It is a class instance used by developers to access the logging module from added modules.

#### Logger Configuration
To use a Logger, three settings need to be configured:
1. Level
2. Handler
3. Filter (optional)

Functions required for configuration:
– `setLevel()`
– `addHandler()`
– `addFilter()`

#### How to Use Logger Functions
– Logger creation: `Logger.getLogger(”)`
– Message creation:
1. `Logger.debug()`, `Logger.info()`, `Logger.warning()`, `Logger.error()`, `Logger.critical() – Default functions
2. `Logger.exception()` – Useful for exception handling
3. `Logger.log()` – For logging with user-defined log levels

These are the fundamental aspects of logging in Python. By understanding these elements and their usage, developers can effectively utilize the logging module to manage and record log information in their applications. The Python documentation provides further details and examples for more advanced logging configurations and functionalities.