Skip to main content

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 set_logdir

logger = easy_logger.RotatingLog(__name__,
                                 logName="sample.log",
                                 logDir=set_logdir("default"),
                                 level="DEBUG",
                                 stream=True,
                                 setLog=True,
                                 setFile=True,
                                 maxBytes=10000,
                                 backupCount=10)
log = logger.getLogger(__name__)
log.info(f"Writting out file to: {set_logdir('default')}")
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:

console output

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: ~/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")
Sample Log File Output Format

[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: ~/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.

Extended Functions

Application Log Directory:

You can set up a subdirectory for your application on a system using the system's default location by leveraging and extension function in the logDir value.

import easy_logger
from easy_logger.utils import set_logdir

logger = easy_logger.RotatingLog(__name__,
                                 logName="sample.log",
                                 logDir=set_logdir("extend", extend="ApplicationName"),
                                 level="DEBUG",
                                 stream=True,
                                 setLog=True,
                                 setFile=True,
                                 maxBytes=10000,
                                 backupCount=10)
log = logger.getLogger(__name__)
log.info(f"log directory set to {logger.settings.logDir}")
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.")
Sample Application Log Directory Output

>>> cat ~/Library/Logs/ApplicationName/sample.log

[2023-07-28 13:03:48,438] level=INFO     name=__main__     fn=<ipython-input-3-edd6755574f8> ln=1 func=<module>: log directory set to ~/Library/Logs/ApplicationName
[2023-07-28 13:03:48,443] level=INFO     name=__main__     fn=<ipython-input-3-edd6755574f8> ln=2 func=<module>: This is an informational log message.
[2023-07-28 13:03:48,446] level=DEBUG    name=__main__     fn=<ipython-input-3-edd6755574f8> ln=3 func=<module>: This is a debug log message.
[2023-07-28 13:03:48,450] level=WARNING  name=__main__     fn=<ipython-input-3-edd6755574f8> ln=4 func=<module>: This is a warning log message.
[2023-07-28 13:03:48,452] level=CRITICAL name=__main__     fn=<ipython-input-3-edd6755574f8> ln=5 func=<module>: This is a critical log message.

Versions

v0.0.6

  • Added color samples as defaults.
  • Created a Color Console only.
  • Updated reformat error to remove [,] characters as it causes issues reading on some systems; replaced with list().
  • Added ability to change Log Format for streaming.

v0.0.5

  • Added a retry decorator.
  • Added Error handler with ability to customize the error return value or ability to log out the error.
  • BUGFIX issue with reformat Exception when added to a JSON object can become problematic so filtering out ugly formating from raised Exception.

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.

Metadata

Release files for py-easy-logger 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-easy-logger 0.0.6
File Size Uploaded Provenance Actions
py-easy-logger-0.0.6.tar.gz 48.4 kB Without provenance Details for py-easy-logger-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-easy-logger 0.0.6
File Interpreter ABI Platform Actions
py_easy_logger-0.0.6-py3-none-any.whl Python 3 none any Details for py_easy_logger-0.0.6-py3-none-any.whl

Total release size: 84.4 kB

Release files / py-easy-logger-0.0.6.tar.gz

Download URL py-easy-logger-0.0.6.tar.gz
Size 48.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6fd8b511b30141e5b18a6ff485197566382c130cca66d9b377e58c6f8a176aa0
BLAKE2b-256 checksum
How to use checksums
fc4be99911cf590a13624f57521a3c7551ca35744c213b0ca1307ed9400257bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / py_easy_logger-0.0.6-py3-none-any.whl

Download URL py_easy_logger-0.0.6-py3-none-any.whl
Size 36.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c21f45af24e53df6d8c40b512c028a7b3d9e9db1b6db59dfceafd049be80ccc
BLAKE2b-256 checksum
How to use checksums
54ffea457dca04303d6be2150971f7a9c3c11f5f2bae36b7bc2e08e4bded6528
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for py-easy-logger 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page