Skip to main content

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
  • Configuration via dlf_settings.json
  • 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.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

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 uses the provided exc object.


Configuration

Configuration is loaded from dlf_settings.json in the current working directory. If the file does not exist, it will be created with defaults on first import.

Example dlf_settings.json:

{
  "custom_prefix": "",
  "use_time": true,
  "use_color": true,
  "use_file_logging": true,
  "log_filename": "log-{get_data}-{get_time}.log"
}

Fields:

  • custom_prefix — custom format string (empty string uses default format)
  • use_time — enable or disable timestamps
  • use_color — enable or disable colors
  • use_file_logging — enable writing logs to a file
  • log_filename — template for log file name, supports {get_data} and {get_time}

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


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.

Metadata

Release files for dlf4p 1.3.0

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

Source distribution (sdist)

Source distribution for dlf4p 1.3.0
File Size Uploaded
dlf4p-1.3.0.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dlf4p 1.3.0
File Interpreter ABI Platform
dlf4p-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / dlf4p-1.3.0.tar.gz

Download URL dlf4p-1.3.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
347468006be71620f1d8931511a665987e81601486c1545cd44474b38c4810f7
BLAKE2b-256 checksum
How to use checksums
2f4a3002c114c100519a3c79e16222399d3569e36f1d5cd3d2d6ac6e59ad14d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / dlf4p-1.3.0-py3-none-any.whl

Download URL dlf4p-1.3.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab88f25ad19fe3322e9d7e254398ee0e1a6c208e59d5e393e3f3c18d95145b20
BLAKE2b-256 checksum
How to use checksums
24c3b2ef31a3cd0ed06ae47befe5e893bdf5f98859f8e6bc29372aa3ba16f7d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

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