Skip to main content

Python 3.7 PyPI version License: MIT Twitter Follow

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")

Metadata

Release files for logging-basic-config 1.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logging-basic-config 1.4.3
File Size Uploaded Provenance Actions
logging_basic_config-1.4.3.tar.gz 3.5 kB Without provenance Details for logging_basic_config-1.4.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for logging-basic-config 1.4.3
File Interpreter ABI Platform Actions
logging_basic_config-1.4.3-py3-none-any.whl Python 3 none any Details for logging_basic_config-1.4.3-py3-none-any.whl

Total release size: 7.7 kB

Release files / logging_basic_config-1.4.3.tar.gz

Download URL logging_basic_config-1.4.3.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
acc5164caa272a8902d486afc8de60f9c1493ec5df259b4075e48c5f1982d9a7
BLAKE2b-256 checksum
How to use checksums
a190cda243f392e28ce7f899c9a09b2ec8c7617661fcf04b36fcee15e3f1c6fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.16

Release files / logging_basic_config-1.4.3-py3-none-any.whl

Download URL logging_basic_config-1.4.3-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5af5be2992e58f3dcbc0bddbd598e0e82fb8cc66db2352e1d8f6be701f9c1e1
BLAKE2b-256 checksum
How to use checksums
a65a977c929ccfbe54ddcb2af8fa014af3cc212741d66bb436263c56438c8a8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.16

Security for logging-basic-config 1.4.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page