Skip to main content

Simple logger

Project description

pyog-log

PyPI version Python 3.7+

Simple python logger (multithreading capable)

Installation :

pip install og-log [-U]

use -U for upgrade from previous version

Usage (basic) :

from og_log import LOG  
LOG.start()  
LOG.debug("Starting application")  
LOG.stop()  

There are 6 level of logging callable with LOG.xxx :
debug,info,warning,error,fatal : standard lines (by priority)
temp : for temporary lines (always visible, max priority, DEL tag to not commit)

You can set priority (default is LEVEL.debug):

from og_log import LOG,LEVEL
LOG.start(level=LEVEL.warning)  # Show all traces >= LEVEL.warning , set at start  
LOG.level(LEVEL.error)          # Change the priority dynamically  

Callbacks :

It works with one or more logging callbacks you can import.
If none is defined at start the ConsoleCallback is default one (standard output display).

Built-in callbacks :

Check code in /callback for constructor parameters

from og_log import ColoredConsoleCallback
Callback Description Key Parameters
ConsoleCallback Plain console output stream (default: stdout)
ColoredConsoleCallback ANSI colored console force_colors, stream
FileLoggerCallback Simple file logger filepath, mode, encoding
RotatingFileLoggerCallback Rotating file with size limit filepath, max_bytes, backup_count , encoding
UDPLoggerCallback Send logs via UDP host, port

Custom callback example :

You can define your own callback inheriting from base class LoggerCallback (check callback dir for built-in examples)

from og_log import LoggerCallback

class EmailCallback(LoggerCallback):
    def init(self):
        self.recipient = self.kwargs['email']
    
    def __call__(self, log_str):
        if ' FTL ' in log_str:     # FATAL
            send_email(self.recipient, log_str)
    
    def close(self):
        pass

LOG.register_cb(EmailCallback(email='admin@example.com'))

Registering/Unregistering callbacks :

LOG.start(callbacks=[ ColoredConsoleCallback() ]) # Set at start, accept single callback or list of callbacks (return list of callback object references)
hdl = LOG.register_cb(ColoredConsoleCallback())   # Add one callback dynamically (return callback object reference)  
LOG.remove_cb(hdl)                                # Remove one callback dynamically  
LOG.remove_all_cb()                               # Remove all callbacks  

Customize display format :

You can customize the log line format using tokens. The default format is:

"%date %level %thread %file %message"

Setting custom format:

from og_log import LOG

# At start
LOG.start(format="%date.ms %level.short [%thread] %file - %message")

# Or dynamically
LOG.set_format("%date.s %level %message")

Available tokens:

Token Description Example Output
%date Full date with microseconds 2025-10-25 14:30:45.123456
%date.us Date with microseconds (same as %date) 2025-10-25 14:30:45.123456
%date.ms Date with milliseconds 2025-10-25 14:30:45.123
%date.s Date with seconds 2025-10-25 14:30:45
%level Level with symbol prefix DBG / ● WRN
%level.short Level name only (3 chars) DBG / WRN
%level.prefix Level with symbol prefix (same as %level) DBG / ● WRN
%level.suffix Level with symbol suffix DBG / WRN ●
%thread Thread name (12 chars padded) MainThread
%file Relative file path and line number src/main.py:42
%message The log message Your log message

Format examples:

# Minimal format
LOG.set_format("%level.short %message")
# Output: DBG Starting application

# Detailed format with milliseconds
LOG.set_format("%date.ms [%thread] %level %file - %message")
# Output: 2025-10-25 14:30:45.123 [MainThread] ● DBG src/main.py:42 - Starting application

# Custom text with tokens
LOG.set_format("[%date.s] <%level.short> %message")
# Output: [2025-10-25 14:30:45] <DBG> Starting application

Note: You can add custom text between tokens. The formatter will preserve spacing and special characters.

Screenshots :

Colored console

image

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

og_log-0.3.2.tar.gz (48.6 kB view details)

Uploaded Source

Built Distribution

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

og_log-0.3.2-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file og_log-0.3.2.tar.gz.

File metadata

  • Download URL: og_log-0.3.2.tar.gz
  • Upload date:
  • Size: 48.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for og_log-0.3.2.tar.gz
Algorithm Hash digest
SHA256 4f5fa3b097944777b5eecc384f1d143f6d3d344a20e634be39ce000800a9d102
MD5 def3928b8e9e25e07336e3494a39c60d
BLAKE2b-256 ebeb4f9e376820ec9d8aa63b36590d48b9aa0e765fbbc6bd0d2d998d0c37411b

See more details on using hashes here.

File details

Details for the file og_log-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: og_log-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 33.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for og_log-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8acf062c94d1c893a306e9aa38b5f5f212d7c35dcd090b3225ba946fd5de20f5
MD5 d87e3a1b6fdd35f533df25173ac41376
BLAKE2b-256 c032815f783d04d0a3f5dd00d9bdfa6c032168af356df8d8135b5e132008f76d

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