GithubHelp home page GithubHelp logo

vtt-info / urollingappenderlog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from inboxidau/urollingappenderlog

0.0 0.0 0.0 20 KB

Simple micropython rolling appender logging

License: MIT License

Python 100.00%

urollingappenderlog's Introduction

uRollingAppenderLog

Quality Gate Status

Simple micropython rolling appender logging.

Send messages to the log file without fear of filling your storage space.

This class allows you to specify

  • the name of the log file
  • the maximum number of bytes you would like to log into a file
  • how many backup versions of the log file you would like to maintain
  • if you also want to print the messages to the console
  • log_level

Backup files are given a suffix indicating how old they are. If max_backup is three then

  • output.log (contains the newest log entries)
  • output.log.1 (contains old log entries)
  • output.log.2 (contains older log entries)
  • output.log.3 (contains oldest log entries)

Files will be deleted when they surpass the max_backups value

Log level allows you to specify both the importance of the logged message and also control which messages are displayed by the logger

Log Level Description
DEBUG Detailed information, typically only of interest when diagnosing problems.
INFO Confirmation that things are working as expected.
ERROR Due to a more serious problem, the software has not been able to perform some function.

The level assigned to the logger shows output

Logger Level DEBUG INFO ERROR
DEBUG
INFO
ERROR

✓ indicates that the corresponding log level will be output.
Blank cells indicate that the corresponding log level will not be output.
The rows represent the log level set for the logger instance.
The columns represent the log levels of the messages.

Messages are logged with the following pattern

  TID:{TID}-{prefix}-{message}

  where
    TID: is a literal string denoting the start of a message.
    {TID} is the UTC timestamp supplied to the log_message function, defaulting to 0000-00-00T00:00:00Z NOTE: the supplied TID is not validated
    {prefix} is a literal string representation of the log_level supplied to the log_message function.
    {message} is the message supplied to the log_message function.

NOTE: Exceptions are not handled within the class and will propogate up the call stack.

# test_logging_app.py

from rolling_appender_log import uRollingAppenderLog, LogLevel

# Instantiate the URollingAppenderLog class with default values
logger = URollingAppenderLog("logger.log")

# Instantiate the URollingAppenderLog class for debugging
logger2 = URollingAppenderLog("logger2.log", LogLevel.DEBUG)

# Instantiate the URollingAppenderLog class for recording only ERROR messages
logger2 = URollingAppenderLog("logger2.log", LogLevel.DEBUG)

# Log messages
logger.log_message("This is an info message.")
logger.log_message("This is another info message.", LogLevel.INFO)
logger.log_message("This is a debug message.", LogLevel.DEBUG)
logger.log_message("This is an error message.", LogLevel.ERROR)
logger.log_message("This is an error message with a specified TID.", LogLevel.ERROR, "2024-01-01T23:59:59Z")

# Log messages
logger2.log_message("This is an info message.")
logger2.log_message("This is another info message.", LogLevel.INFO)
logger2.log_message("This is a debug message.", LogLevel.DEBUG)
logger2.log_message("This is an error message.", LogLevel.ERROR)
logger2.log_message("This is an error message with a specified TID.", LogLevel.ERROR, "2024-01-01T23:59:59Z")

If you want to specify the maximum size of a log file in bytes along with the number of backup files or print messages you can adjust the instantiation

# test_logging_app.py

from rolling_appender_log import uRollingAppenderLog, LogLevel

# Instantiate the URollingAppenderLog class with custom values
logger = URollingAppenderLog("test_log.log", max_file_size_bytes=1024, max_backups=3, print_messages=True, LogLevel.DEBUG)

# Log a message
logger.log_message("This is a test message.")

urollingappenderlog's People

Contributors

inboxidau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.