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  

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.2.1.tar.gz (46.4 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.2.1-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: og_log-0.2.1.tar.gz
  • Upload date:
  • Size: 46.4 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.2.1.tar.gz
Algorithm Hash digest
SHA256 697935d129371764b1daeed63260d2298e306b276584c5f210bbefa604533247
MD5 e068023e15809c1aaeac4a466391a8c3
BLAKE2b-256 e0a052659076aa7091dd9f657654b2dcd2663f4318509bfe83d326da359b2724

See more details on using hashes here.

File details

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

File metadata

  • Download URL: og_log-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 31.8 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd9eb6d867c3c936a02df53736349444fba2a8ed5f729e2f5a38ee97ea57c82e
MD5 b2748776fee0f728bef9746e5dbcfc9e
BLAKE2b-256 6f1375f1f4ab803f13b3b6690dd1385c16c6d8171a85dee2edc3f50dae9b158f

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