Skip to content

Project-Collapse-Studios/PCSLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PCSLogger

A custom logging library for python.

Usage is pretty simple. Every time you need to access the logger you import the Logger object:

from pcslogger import Logger

This Logger object has two particularly interesting methods: RegisterMainApplication and RegisterModule. Both of them return an actual logger class that you can call Info, Warning, Error, Critical and their verbose (VInfo, VWarning, ...) counterparts to log into various handlers.

Calling these methods will result in a message being printed (example): <I>|[App Name][Module Name]: Message

For ease of use, by default logging into stdout is enabled. For ease of use, logging to file setup was streamlined, you should use the EnableFileLogging method (on Logger) that takes the log path as a parameter. This will create log files log, log_1, log_2, ... where the latter are log backups, up to the number specified.

It is possible to add/remove other handlers from python's logging library, by calling AddHandler/RemoveHandler on the Logger object

Example usage main.py:

import mylibrary
import pcslogger

MainLogger = pcslogger.Logger.RegisterApplication("MyCoolApp", False, pcslogger.Level.INFO, True)

MainLogger.Info("Hi!")
mylibrary.PrintMsg()

mylibrary.py:

import pcslogger
Logger = pcslogger.Logger.RegisterModule("mylibrary")

def PrintMsg():
    Logger.Info("Hello from mylibrary!")

This will print out:

<I>|[MyCoolApp]: Hi!
<I>|[MyCoolApp][mylibrary]: Hello from mylibrary!

Note: The pcslogger.Logger is an already initialized version of LoggerMgr. It is absolutely possible to create another one and have multiple LoggerMgr objects available for multiple applications at once. Logger is only there for ease of use in one project - one program applications.

About

A custom logging library for python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages