A lightweight Python logging wrapper that simplifies Python's standard logging module
Project description
Simplified Logger
A lightweight Python logging wrapper that simplifies the use of Python's standard logging module. This library provides an easy-to-use interface for logging to both console and files with minimal configuration.
Features
- Simple API: Clean and intuitive methods for all log levels
- File & Console Logging: Support for both file and console handlers
- Formatted Output: Pre-configured formatting with timestamps and log levels
- Auto Directory Creation: Automatically creates log directories if they don't exist
- Duplicate Prevention: Built-in checks to prevent duplicate handler initialization
- Multiple Log Levels: Support for INFO, DEBUG, WARNING, ERROR, and CRITICAL levels
Installation
Clone the repository or copy the lib/standard-logger.py file to your project:
pip install simplified-logging
Or simply download the file and place it in your project directory.
Usage
Basic Example
from std_log import Logger
# Initialize the logger
logger = Logger(name="app.log", dir="logs")
# Add console handler (outputs to terminal)
logger.console_handler()
# Add file handler (writes to file)
logger.file_handler()
# Log messages at different levels
logger.info("Application started successfully")
logger.debug("Debugging information")
logger.warn("This is a warning message")
logger.error("An error occurred")
logger.critical("Critical system failure")
Console-Only Logging
from std_log import Logger
logger = Logger()
logger.console_handler()
logger.info("This will only appear in the console")
File-Only Logging
from std_log import Logger
logger = Logger(name="app.log", dir="logs")
logger.file_handler()
logger.info("This will only be written to .logs/app.log")
Custom Log Directory
from std_log import Logger
# Logs will be stored in .my-logs/application.log
logger = Logger(name="application.log", dir="my-logs")
logger.file_handler()
Recommended Pattern
from std_log import Logger
class AppWatcher(Logger):
def __init__(self, name: str, dir:Optional[str] = None):
super().__init__(dir = dir or 'logs', name=f"{self.__class__.__name__} -- {name}.log")
logger = AppWatcher(name="service.log", dir="logs")
logger.file_handler()
logger.info("Service started")
API Reference
Logger Class
__init__(name: str, dir: str)
Initialize a new logger instance.
- name: Name of the log file (e.g., "app.log")
- dir: Directory name where logs will be stored (prefix with '.' automatically added)
console_handler() -> None
Adds a console handler to output logs to the terminal/console.
file_handler() -> None
Adds a file handler to write logs to a file. Creates the directory if it doesn't exist.
info(message: str)
Logs an informational message (INFO level).
debug(message: str)
Logs a debug message (DEBUG level). Useful for detailed diagnostic information.
warn(message: str)
Logs a warning message (WARNING level).
error(message: str)
Logs an error message (ERROR level).
critical(message: str)
Logs a critical message (CRITICAL level). For severe errors that may cause application failure.
Log Format
The logger uses the following format for all messages:
%(asctime)s - %(levelname)-8s - %(name)s - %(message)s
Example output:
2026-03-09 10:30:45,123 - INFO - app.log - Application started successfully
2026-03-09 10:30:46,456 - WARNING - app.log - This is a warning message
2026-03-09 10:30:47,789 - ERROR - app.log - An error occurred
Requirements
- Python 3.7+
- No external dependencies (uses standard library only)
Project Structure
simplified-logger/
├── .git/
├── .github/
├── .vscode/
├── LICENCE
├── README.md
├── pyproject.toml
└── std_log/
├── __init__.py
└── standard-logger.py
License
Author
krigjo25 - krigjo25@gmail.com
Support
If you encounter any issues or have questions, please open an issue on the GitHub repository.
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
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
File details
Details for the file simplified_logging-1.0.14.tar.gz.
File metadata
- Download URL: simplified_logging-1.0.14.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
556a91729655fadb3039895828fbd086e77d77fa5c573af7aced41ce11b7ed4d
|
|
| MD5 |
3de85ef560f3529054ebb089b08a3878
|
|
| BLAKE2b-256 |
c3d05631bd17dc869356a7206267452fb1e468239d886fc52cd9ae63d57b5156
|
Provenance
The following attestation bundles were made for simplified_logging-1.0.14.tar.gz:
Publisher:
publish-package-pypi.yml on krigjo25/simplified-logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simplified_logging-1.0.14.tar.gz -
Subject digest:
556a91729655fadb3039895828fbd086e77d77fa5c573af7aced41ce11b7ed4d - Sigstore transparency entry: 1437541157
- Sigstore integration time:
-
Permalink:
krigjo25/simplified-logger@824e5de17af4df3d044e707478c5eac78fecccf0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/krigjo25
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package-pypi.yml@824e5de17af4df3d044e707478c5eac78fecccf0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file simplified_logging-1.0.14-py3-none-any.whl.
File metadata
- Download URL: simplified_logging-1.0.14-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e7fd01937fe3dffd435aba491c22e9cf6e6a7954abda7238ca5c19a01306b76
|
|
| MD5 |
12afac6d3fd71595abb45512bbfa763c
|
|
| BLAKE2b-256 |
8b4db20c92e7b0cc01dcc10630107adad2ba0889a06af7c08c6c6337a838944b
|
Provenance
The following attestation bundles were made for simplified_logging-1.0.14-py3-none-any.whl:
Publisher:
publish-package-pypi.yml on krigjo25/simplified-logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simplified_logging-1.0.14-py3-none-any.whl -
Subject digest:
9e7fd01937fe3dffd435aba491c22e9cf6e6a7954abda7238ca5c19a01306b76 - Sigstore transparency entry: 1437541159
- Sigstore integration time:
-
Permalink:
krigjo25/simplified-logger@824e5de17af4df3d044e707478c5eac78fecccf0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/krigjo25
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package-pypi.yml@824e5de17af4df3d044e707478c5eac78fecccf0 -
Trigger Event:
push
-
Statement type: