Skip to main content

The simplest Python logger for everyday tasks.

Project description

loggerpy

The simplest Python logger for everyday tasks.

Table of Contents

Installation

The easiest way to install is throw pip.

pip install loggerpy

Or you can install directly from Github

pip install git+https://github.com/mett96/loggerpy.git

Instructions

In order to use this simple logger, many examples are provided inside examples directory

logging

Configuration

The first thing to do is to configure the global settings of logger package.

import loggerpy

loggerpy.configure()

The possible customization of configurations are:

  • domain: the main name of all loggers
  • path: the path of saving log if you want to save them
  • print_level: the minimum level of printing
  • save_level: the minimum level of saving, they can be different
  • info: boolean value if you want to print the default string "Logger configured..."

In order to simplify the customization of printing and saving level it is provided a class that contained the 6 possible levels of logging. Importing Level from loggerpy, they can be used eg Level.DEBUG or Level.WARNING

  • Level.NO_LOGGER
  • Level.DEBUG
  • Level.INFO
  • Level.WARNING
  • Level.ERROR
  • Level.CRITICAL

Configuration example

Logger

Now, it's time to create your first logger.

from loggerpy import configure, get_logger

configure()

logger = get_logger('custom_name')

First logger example

Customization

When we use get_logger we can set custom parameters for this specific logger. They are independent from the parameters set during configuration. The customizable parameters are:

  • print_level
  • save_level
  • path
logger = get_logger('first', print_level=Level.WARNING, save_level=Level.INFO, path='path_of_log')

The complete example

LoggerRecovery

Each logger has a unique name. So, when you ask to get_logger to create a logger with an already existing name, it returns an instance of the unique logger with input name.
Only in this case, if it is given also a custom path it is ignored in order to not split the logs into different files

logger = get_logger('unique_name')
logger1 = get_logger('unique_name')

print(logger1 == logger)
print(hash(logger))
print(hash(logger1))

The equality of the two loggers can be verified by printing the result of the equality of the two objects, or printing the hash of each object.

The complete the in the linkes example

Versions

stable version

  • 1.0 : released

development version

  • 1.1 : on going
    • [ ] introducing pprint and json to print better log
    • [ ] try to expose _Level methods without give the possibility to create a new object
    • [ ] review path of saving log
    • [ ] the configuration works only in one file not over all package

NextRelease

  • [ ] custom format for timestamp
  • [ ] custom format for all log
  • [ ] custom color for each level
  • [ ] inherit the domain from another logger

License

This project is under the GPL-3.0 license - see the LICENSE.md file for more details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for loggerpy, version 1.1
Filename, size File type Python version Upload date Hashes
Filename, size loggerpy-1.1-py3-none-any.whl (20.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size loggerpy-1.1.tar.gz (8.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page