A simple Python logger with colors and file output
Project description
smlog
A simple Python logger with colored console output, optional file logging, and daily log rotation.
Features
- Colored console output for different log levels (DEBUG, INFO, WARNING, ERROR)
- Optional logging to files with automatic directory creation
- Daily log rotation
- Minimal setup and easy-to-use interface
- Customizable minimum log level
- Unlimited amount of parameters for logging
Installation
pip install smlog
Create a logger
from smlog import Logger
logger = Logger(
name="user",
min_level="INFO",
use_colors=True,
log_to_file=True,
log_dir="logs",
rotate_daily=True
)
Example
from smlog import Logger
logger = Logger(
name="user",
min_level="INFO",
use_colors=True,
log_to_file=True,
log_dir="logs",
rotate_daily=True
)
logger.log("info", "Server has been started", user="user") # user is a parameter, u can add as many as u need to
or
logger.info("Server has been started", role="admin") # role is a parameter, u can add as many as u need to
Exception
try:
1 / 0
except Exception as e:
logger.error("This is an error message", exc=e)
Log messages of different levels
- logger.debug("This is a debug message") # Will not be shown if min_level is INFO
- logger.info("This is an info message")
- logger.warning("This is a warning")
- logger.error("This is an error")
Logging to File
Logs are saved to the specified log_dir
File names are either log.log or daily rotated (YYYY-MM-DD.log)
Each log entry is separated for clarity:
[2026-01-25 23:45:12] [WARNING] [user] message
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
smlog-1.1.0.tar.gz
(3.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
smlog-1.1.0-py3-none-any.whl
(4.2 kB
view details)
File details
Details for the file smlog-1.1.0.tar.gz.
File metadata
- Download URL: smlog-1.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25ef8a221c8550f0bfd395188282e5a552b11c37e3cbafac3020d4ab1155d196
|
|
| MD5 |
791eb55a6dd0e8f9e191eb664295291a
|
|
| BLAKE2b-256 |
7903f5fcdb646aa554fd03f4b7c8ce30847b867f0ddf226ccc0c852ce936eea3
|
File details
Details for the file smlog-1.1.0-py3-none-any.whl.
File metadata
- Download URL: smlog-1.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd50628f723eaf89931d64e4a21f09970b77afc3f34b7a283ad25f26fd2c9dbf
|
|
| MD5 |
2be61f75c7b31fb41186498f9fc411ff
|
|
| BLAKE2b-256 |
59023e51a422464191e31768544ced292cdba359b8571cc29024b1643d73380c
|