Basic logging configurations to easily use in many projects
Project description
Basic Python Logging Configuration
This is a Python pip package that provides a simple function called config()
that sets up the logging configuration for a Python project.
How it Works
The config()
function takes in three optional arguments: logging_level
, libs_to_silence
, and env_var_hide_timestamp
.
logging_level
specifies the minimum logging level that should be recorded. The default value is "INFO".libs_to_silence
is a list of external libraries whose logging should be silenced. By default, several commonly used libraries are silenced.env_var_hide_timestamp
is an environment variable that can be set to hide the timestamp in the log messages.
The function then proceeds to set up the logging configuration based on the provided arguments. It first sets the logging level for external libraries to logging.ERROR
.
Next, it checks the LOGGING_LEVEL
environment variable and uses its value if it is set, otherwise it uses the logging_level
argument.
The log format is then set depending on whether env_var_hide_timestamp
is set or not. If it is set, the format only includes the log level, filename, and line number. Otherwise, the format includes the timestamp, log level, filename, and line number.
Finally, the function creates a StreamHandler
that logs to the standard output, sets the formatter to the log format, adds the handler to the logger, and sets the logging level to the specified level.
The logger is then returned so that it can be used throughout the project to log messages at the specified level.
Overall, logging_basic_config
simplifies the process of configuring logging in a Python project, making it easier to customize the logging level and format, and to silence external libraries.
Example
Install package
pip install logging-basic-config
Using the library
import logging_basic_config
logging = logging_basic_config.config(logging_level="DEBUG")
logging.debug("Debug message")
logging.info("Info message")
logging.warning("Warning message")
logging.error("Error message")
logging.critical("Critical message")
In additional files
Once the logging_basic_config.config(logging_level="DEBUG")
code was called in your main
or entrypoint call, you only need to import logging
and use it in other files.
import logging
logging.info("This is another info message")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for logging_basic_config-1.4.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | acc5164caa272a8902d486afc8de60f9c1493ec5df259b4075e48c5f1982d9a7 |
|
MD5 | 4d1cdf887654da9384feccee14d48e29 |
|
BLAKE2b-256 | a190cda243f392e28ce7f899c9a09b2ec8c7617661fcf04b36fcee15e3f1c6fd |
Hashes for logging_basic_config-1.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5af5be2992e58f3dcbc0bddbd598e0e82fb8cc66db2352e1d8f6be701f9c1e1 |
|
MD5 | f90c8d1a70303e9b66bb6e03069a7fb9 |
|
BLAKE2b-256 | a65a977c929ccfbe54ddcb2af8fa014af3cc212741d66bb436263c56438c8a8b |