Easy Logger
Project description
easy-logger
Simple Easy baseline Logger. Creates a color stream logger or a basic rotating logger that can be used and called on throughout a project.
Usage
Configuration Values:
- name: Name of file can use built in __name__ or specifiy a name to call the logger instance.
- logName: filename for log.
- logDir: Directory location to store log.
- Can use built in utilitiy to find the default log location for the system you are on.
- level: Log Level. Can be one of the following Strings.
- NOTSET = 0
- DEBUG = 10
- INFO = 20
- WARN = 30
- WARNING = 30
- ERROR = 40
- CRITICAL = 50
- FATAL = 50
- setFile: Bool Value to set the logger to write out to file.
- stream: Bool Value to allow conosole output of log.
- maxBytes: Maximum Byte size before rotating log file.
- backupCount: Amount of backups to keep.
- setLog: Enables or creates the logging instance otherwise will not log anything.
import easy_logger
from easy_logger.utils import get_log_dir
logger = easy_logger.RotatingLog(__name__,
logName="sample.log",
logDir=get_log_dir(),
level="DEBUG",
stream=True,
setLog=True,
setFile=True,
maxBytes=10000,
backupCount=10)
log = logger.getLogger(__name__)
log.info(f"Writting out file to: {get_log_dir()}")
log.info("This is an informational log message.")
log.debug("This is a debug log message.")
log.warning("This is a warning log message.")
log.critical("This is a critical log message.")
What this will look like in the console:
If written to file:
>>> cat ~/Library/Logs/sample.log
[2023-07-19 12:25:01,648] level=INFO name=__main__ fn=<ipython-input-1-e1c5bba1549c> ln=14 func=<module>: Writting out file to: /Users/*****/Library/Logs
[2023-07-19 12:25:01,650] level=INFO name=__main__ fn=<ipython-input-1-e1c5bba1549c> ln=15 func=<module>: This is an informational log message.
[2023-07-19 12:25:01,652] level=DEBUG name=__main__ fn=<ipython-input-1-e1c5bba1549c> ln=16 func=<module>: This is a debug log message.
[2023-07-19 12:25:01,658] level=WARNING name=__main__ fn=<ipython-input-1-e1c5bba1549c> ln=17 func=<module>: This is a warning log message.
[2023-07-19 12:25:01,667] level=CRITICAL name=__main__ fn=<ipython-input-1-e1c5bba1549c> ln=18 func=<module>: This is a critical log message.
If the name value is passed as a string instead of using the python file name the name will show up in the logs such as:
log = logger.getLogger("easy_logger")
[2023-07-19 12:34:53,266] level=INFO name=easy_logger fn=<ipython-input-2-297430e75a74> ln=14 func=<module>: Writting out file to: /Users/*******/Library/Logs
[2023-07-19 12:34:53,268] level=INFO name=easy_logger fn=<ipython-input-2-297430e75a74> ln=15 func=<module>: This is an informational log message.
[2023-07-19 12:34:53,268] level=DEBUG name=easy_logger fn=<ipython-input-2-297430e75a74> ln=16 func=<module>: This is a debug log message.
[2023-07-19 12:34:53,269] level=WARNING name=easy_logger fn=<ipython-input-2-297430e75a74> ln=17 func=<module>: This is a warning log message.
[2023-07-19 12:34:53,269] level=CRITICAL name=easy_logger fn=<ipython-input-2-297430e75a74> ln=18 func=<module>: This is a critical log message.
NOTE: It is usually best practice when passing a logger around a large project to pick up the name of the file and the function for easier troubleshooting depending on what method you use.
Versions
v0.0.4
- Added utility to find OS Log directory.
- Added Splunk JSON data formatter.
v0.0.3
- Added Splunk basic string log out format.
- Added Splunk HEC JSON format for messaging.
Future Enhancements
- Use a standard or basic logger.
- Allow conversion of int/str types for log level.
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
py-easy-logger-0.0.4.tar.gz
(43.6 kB
view hashes)
Built Distribution
Close
Hashes for py_easy_logger-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7223e26a376ce6d9eb8ff0e48faed3c103b159f50c465d37ab71a8111168bda2 |
|
MD5 | bde65193987f0d05dea8a9e030ebe1f1 |
|
BLAKE2b-256 | 8dcfe84ab0167e0e5b49000624b8a4795e00d4495761a3ec34180561e843cd40 |