A simple logger that prints logs to the console and to a file out of the box.
Project description
pynlog: A Simple Python Logging Library
pynlog is a lightweight, static logging library for Python, designed for simplicity and ease of use.
It provides a convenient way to log messages at different levels (DEBUG, INFO, SUCCESS, WARNING, ERROR) without the complexity of traditional logging setups.
It defaults to logging to both the console and a file.
Key Features
- Simple & Static: Easy-to-use static methods for logging - no class instantiation needed. The logger automatically determines the function or module where the log message originated, providing context without requiring manual input.
- Highly Customizable:
FormattersandWriterscan be tailored to your needs. - Dual Output: Logs to both the console and a file by default.
- Lightweight: Minimal dependencies and a compact codebase.
Installation
pip install pynlog
Usage
When used by a function
from pynlog import Log
def my_function():
Log.d("This is a debug log.")
Log.i("This is an info log.")
Log.s("This is a success log.")
Log.w("This is a warning log.")
Log.e("This is an error log.")
my_function()
Output
[2025-10-22 16:50:56.409] [DEBUG] my_function : This is a debug log.
[2025-10-22 16:50:56.409] [INFO] my_function : This is an info log.
[2025-10-22 16:50:56.409] [SUCCESS] my_function : This is a success log.
[2025-10-22 16:50:56.409] [WARNING] my_function : This is a warning log.
[2025-10-22 16:50:56.409] [ERROR] my_function : This is an error log.
When used by a class method
from pynlog import Log
class MyClass():
def my_function(self):
Log.d("This is a debug log.")
Log.i("This is an info log.")
Log.s("This is a success log.")
Log.w("This is a warning log.")
Log.e("This is an error log.")
MyClass().my_function()
Output
[2025-10-22 16:57:15.178] [DEBUG] MyClass.my_function : This is a debug log.
[2025-10-22 16:57:15.178] [INFO] MyClass.my_function : This is an info log.
[2025-10-22 16:57:15.178] [SUCCESS] MyClass.my_function : This is a success log.
[2025-10-22 16:57:15.178] [WARNING] MyClass.my_function : This is a warning log.
[2025-10-22 16:57:15.178] [ERROR] MyClass.my_function : This is an error log.
Customization
1. Adjusting the Minimum Log Level
The default minimum level is DEBUG. Change it to suppress less important messages.
from pynlog import Log, Level
def my_function():
Log.d("This is a debug log.")
Log.MIN_LEVEL = Level.INFO
Log.d("This log will not show up.")
Log.i("This is an info log.")
my_function()
Output
[2025-10-22 17:01:15.795] [DEBUG] my_function : This is a debug log.
[2025-10-22 17:01:15.795] [INFO] my_function : This is an info log.
2. Creating a Custom Formatter
Tailor the appearance of your log messages.
from pynlog import Log, Formatter, LogEntry
class MyFormatter(Formatter):
def format(self, entry: LogEntry) -> str:
return f"[{entry.level.name}] {entry.caller}: {entry.message}"
def my_function():
Log.i("This is an info log using the default formatter.")
Log.FORMATTER = MyFormatter()
Log.i("This is an info log using MyFormatter.")
my_function()
Output
[2025-10-22 17:04:15.480] [INFO] my_function : This is an info log using the default formatter.
[INFO] my_function : This is an info log using MyFormatter.
3. Adding/Removing Writers
Control where your logs are sent:
-
Adding a Writer
from pynlog import Log, Writer class MyWriter(Writer): def write(self, message: str) -> None: print(f"Sending to custom destination: {message}") def my_function(): Log.i("Writing to default writers.") Log.WRITERS["my_writer"] = MyWriter() Log.i("Writing to default and new writers.") my_function()
Output
[2025-10-22 17:09:13.531] [INFO] my_function : Writing to default writers. [2025-10-22 17:09:13.531] [INFO] my_function : Writing to default and new writers. Sending to custom destination: [2025-10-22 17:09:13.531] [INFO] my_function : Writing to default and new writers. -
Removing a Writer
from pynlog import Log def my_function(): Log.i("This is an info log.") del Log.WRITERS["console_writer"] Log.i("This will not be logged.") my_function()
Output
[2025-10-22 17:11:21.106] [INFO] my_function : This is an info log.
License
This project is licensed under the MIT License.
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 pynlog-0.1.1.tar.gz.
File metadata
- Download URL: pynlog-0.1.1.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43eb028e76f26c6cd77b7834f4268950051971db374ccc859bae0aade82ad493
|
|
| MD5 |
4f2f21283f092939861f75542e3f492f
|
|
| BLAKE2b-256 |
96a942c6d1e91e0171cab4df27b27da92ed345010d6f69aa3f9dcfc560d1e7d2
|
File details
Details for the file pynlog-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pynlog-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9bde17fbbd7b8910dff2f9cd4d1df87c5f72fc202ce0dd41ab341b446be859e
|
|
| MD5 |
70e2e021da393924b0ef7c8cad705f20
|
|
| BLAKE2b-256 |
87aa66e67cb0aa0a10e1077914153fa0faa3214518bf5c857e4a6852f73bb852
|