Skip to main content

A simple logger made primarily for my own personal use. Made from a combination of necessity and so much sloth that it overflowed into productivity.

Project description

smooth_logger

A simple logger made primarily for my own personal use. Was made out of a combination of necessity and being so lazy that I overflowed into being productive and instead of searching for a library that suited my needs, I wrote my own.

Installation

smooth-logger can be installed through pip. Either download the latest release from Codeberg/GitHub, or do pip install smooth-logger to install from PyPi. For the latest commits, check the dev branches on the repositories.

smooth-logger was written in Python 3.9, but should work with Python 3.5 and up. A minimum of 3.5 is required due to the project's use of type hinting, which was introduced in that version.

smooth-logger supports Linux, macOS and Windows.

Usage

Usage of smooth-logger is, as it should be, quite simple.

The Logger model provides a number of methods for your use:

  • Logger.clean() erases all log entries currently in memory.
  • Logger.get() allows you to retrieve either the most recent log entry or all log entries, optionally filtered by scope.
  • Logger.get_time() returns the full date & time, or optionally just the date, in ISO-8601 formatting.
  • Logger.init_bar() initialises the ProgressBar model imported from the smooth_progress dependency.
  • Logger.notify() sends a desktop notification using the plyer dependency.
  • Logger.new() creates and, depending on scope, prints a new log entry.
  • Logger.output() saves all log entries of appropriate scope to the log file and cleans the log array for the next group of log entries. A new log file is created for each new day. This method only attempts to create or update the log file if there are entries of an appropriate scope to be written to it; if there are none, it just executes Logger.clean().

When initialising the Logger, you can optionally provide values to associate with each scope:

  • 0: disabled, do not print to console or save to log file
  • 1: enabled, print to console but do not save to log file
  • 2: maximum, print to console and save to log file

The scopes available, along with their default values and suggested use cases, are:

  • DEBUG (0): Information for debugging the program.
  • ERROR (2): Errors that the program can recover from but impact functionality or performance.
  • FATAL (2): Errors that mean the program must continue; handled crashes.
  • INFO (1): General information for the user.
  • WARNING (2): Things that have no immediate impact to functionality but could cause errors later on.

Here is a simple example showing the initialisation of the logger:

import smooth_logger

Log = smooth_logger.Logger("Example", "~/.config/example")
Log.new("This is a log message!", "INFO")

Roadmap

A roadmap of planned future improvements and features:

  • Allow the creation of custom scopes. These would be instance-specific and not hard saved in any way. Suggested format and example:

    Log.add_scope(name: str, description: str, default_value: int)
    
    Log.add_scope("NEWSCOPE", "A new scope of mine!", 1)
    

    Potentially also allow removal of scopes. In this situation, default scopes should be removable, but doing so should log a warning.

  • Allow editing of the values of existing scopes post-initialisation. For example:

    Log.edit_scope(name: str, new_value: int)
    
    Log.edit_scope("DEBUG", 1)
    

    to temporarily enable debug statements. This feature would probably see the most use from custom scopes.

  • Add an optional argument notify: bool to Logger.new() to allow log entries to be created and notified in one statement, rather than the two currently required.

  • Rework Logger.get() to allow passing of a specific number of log values to be fetched. If these values exceed the number in the log, all matching log values should be returned, and a warning should be issued (but not returned).

  • Possibly replace some internal warnings with Exceptions so they can be more easily-handled by end-user programs.

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

smooth_logger-0.2.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smooth_logger-0.2.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file smooth_logger-0.2.0.tar.gz.

File metadata

  • Download URL: smooth_logger-0.2.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for smooth_logger-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ee17cab82a23d2c970da899ac3a8efe7545a1dd55c713b60a0c5d658bda735fb
MD5 af17ee755a1742beaf9af981e7fc7a97
BLAKE2b-256 5025a5989987af57bdce8b144ff1aeaa210b3f7e152a091303402489a4da44fb

See more details on using hashes here.

File details

Details for the file smooth_logger-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: smooth_logger-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for smooth_logger-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 245f692f26c256dc7890a983a7885f26772f9549152df6ffe08a47eb782a0bfd
MD5 6caff5991c906d523a6aaecc655aaecf
BLAKE2b-256 a0c7226c631afcc2f1cee574e21387f015e6e11295e42f74a42ccb97b66e6c4f

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