Skip to main content

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: Formatters and Writers can be tailored to your needs.
  • Dual Output: Logs to both the console and a file by default.
  • Lightweight: Minimal dependencies and a compact codebase.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynlog-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

pynlog-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file pynlog-0.1.0.tar.gz.

File metadata

  • Download URL: pynlog-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pynlog-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39c066b79f1756823bb668067f80628365ed60774f435a64840e90d0c36d8fca
MD5 101b6f3425eecd10fd611d2380196fbd
BLAKE2b-256 6d2e73cfbb7e460c874dbd7ddddd14d0a318109977c065689ae7426b33ff2a35

See more details on using hashes here.

File details

Details for the file pynlog-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pynlog-0.1.0-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

Hashes for pynlog-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 636bcc536e159bce306bac170fe490b674a222a1326830bdfef30f4161cfaa8c
MD5 86fed3d790ccc1e97540f6e95669efe7
BLAKE2b-256 9e15cc55b387cabbf7ad970eb4e9ff042a3809989408f546ed227c5dea4aaaa1

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