Skip to main content

Dexoron Logging Framework for Python

Project description

dlf4p — Dexoron Logging Framework for Python

dlf4p is a lightweight and convenient logger for Python inspired by SLF4J. It provides a simple API for logging messages with support for log levels, colored console output, timestamps, and file logging.

The project is being developed as part of the DLF (Dexoron Logging Framework) family, with plans for implementations in other programming languages.

GitLab repository: https://gitlab.com/dexoron/dlf4p PyPi project: https://pypi.org/project/dlf4p


Features

  • Log levels: DEBUG, INFO, SUCCESS, WARNING, ERROR, FATAL, EXCEPTION
  • Colored console output
  • Timestamp support
  • Prefix support (e.g., module or component name)
  • File logging
  • Simple configuration via setup()
  • Traceback output for exceptions
  • Exception logging helper: exception()
  • Lightweight and with no external dependencies

Installation

Install from PyPI:

pip install dlf4p

Quick Start

import dlf4p as dlf 

dlf.setup(time=True, color=True, simple=False, file_logging=True)

dlf.info("Application started", "Main")
dlf.success("Server successfully started", "Server")
dlf.warning("Slow response", "API")
dlf.error("Database connection error", "Database")
dlf.fatal("Critical error", "System")

try:
    1 / 0
except Exception as e:
    dlf.error("Division failed", "Math", exc=e)
    dlf.exception("Unhandled error", "Math", exc=e)

Console output:

[14:24:56] [Main/INFO]: Application started
[14:24:56] [Server/SUCCESS]: Server successfully started
[14:24:56] [API/WARNING]: Slow response
[14:24:56] [Database/ERROR]: Database connection error
[14:24:56] [System/FATAL]: Critical error
[14:24:56] [Math/ERROR]: Division failed
Traceback (most recent call last):
  File "/home/probrovova/project/dlf-py/test/main.py", line 30, in <module>
    1 / 0
ZeroDivisionError: division by zero
[14:24:56] [Math/EXCEPTION]: Unhandled error
Traceback (most recent call last):
  File "/home/probrovova/project/dlf-py/test/main.py", line 30, in <module>
    1 / 0
ZeroDivisionError: division by zero

Logger class example:

import dlf4p as dlf

dlf.setup(time=True, color=True, simple=False, file_logging=True)

log = dlf.Logger("Main")
log.info("Application started")

log = dlf.Logger("Core")
log.setLevel(2)  # SUCCESS and higher
log.info("Core module initialized")
log.success("Submodule loaded successfully")
log.warning("Disabled System modules")

try:
    raise ValueError("Bad value")
except Exception as e:
    log.exception("Something went wrong", exc=e)

Console output:

[14:26:59] [Main/INFO]: Application started
[14:26:59] [Core/INFO]: Log level set to SUCCESS
[14:26:59] [Core/SUCCESS]: Submodule loaded successfully
[14:26:59] [Core/WARNING]: Disabled System modules
[14:26:59] [Core/EXCEPTION]: Something went wrong
Traceback (most recent call last):
  File "/home/probrovova/project/dlf-py/test/main.py", line 31, in <module>
    raise ValueError("Bad value")
ValueError: Bad value

Logs are saved to a file without ANSI color codes. Traceback output requires an active exception (inside an except block).


Configuration

The setup() function is used to configure the logger:

dlf.setup(
    time=True,        # show timestamp
    color=True,       # enable colored output
    simple=False,     # simplified log format (without prefixes)
    file_logging=True # enable file logging
)

Parameters:

  • time — enable or disable timestamps
  • color — enable or disable colors
  • simple — disable prefixes
  • file_logging — enable writing logs to a file

Run Example

From the project root:

python3 -m test.main

Philosophy

dlf4p is inspired by SLF4J (Simple Logging Facade for Java) and aims to:

  • provide a simple and unified logging interface
  • remain minimalistic
  • have no external dependencies
  • be easily extensible to other programming languages

License

This project is licensed under the MIT License. See the LICENSE file for details.


Author

Dexoron

GitLab: https://gitlab.com/dexoron GitHub: https://github.com/dexoron Website: https://dexoron.su


Project Links

Changelog: CHANGELOG
Contributing guide: CONTRIBUTING.md GitLab repository: https://gitlab.com/dexoron/dlf4p PyPi project: https://pypi.org/project/dlf4p


dlf4p — a simple logger today, a full logging framework tomorrow.

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

dlf4p-1.2.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dlf4p-1.2.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file dlf4p-1.2.2.tar.gz.

File metadata

  • Download URL: dlf4p-1.2.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for dlf4p-1.2.2.tar.gz
Algorithm Hash digest
SHA256 aadb77983ecd4ae5e253d7c6eb331428207e8a0d75fa76d9ca76a1b5b6766fda
MD5 23bd758fd3cad4f857371c3d27b7f579
BLAKE2b-256 e643a12fff3ecbd4bb42ed5d634b25b13c94ba62e07b031d24ddb2434b2cfab8

See more details on using hashes here.

File details

Details for the file dlf4p-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: dlf4p-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for dlf4p-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5512468efda57c76b03b8a073edede6e737d8d8992b84504aaa4f737f116e080
MD5 9c8c049f37be1673538891d6340fa6f3
BLAKE2b-256 017800ecb133f413fbb2a262bdb09437b074f77b89f05f1ecfa829f5c6d853a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page