Skip to main content

A logger for python

Project description

Gamu Logger - Python Version

📚 Table of Contents

🔨 Installation

The package is available in the assets of the latest release on pypi.

You can install it with pip(recommended):

pip install gamuLogger

Or from github:

pip install https://github.com/GamuNetwork/logger/releases/download/2.0.0/gamu_logger-2.0.0-py3-none-any.whl

note: replace 2.0.0 with the version number you want to install.

💡 Usage

  • First you need to import the package:
    from gamuLogger import deepDebug, debug, info, warning, error, critical, Logger, LEVELS, SENSITIVE_LEVELS
    

note: you can also only import the members you need instead of importing all of them.

  • Then you can use the functions like this:
    info('This is an info message')
    warning('This is a warning message')
    error('This is an error message')
    

You may note that the logging function are also available as static methods in the Logger class. This allow you to have them encapsulated in a class and use them in a more object > oriented way:

from gamuLogger import Logger

Logger.info('This is an info message')
Logger.warning('This is a warning message')
Logger.error('This is an error message')

⚙️ Configuration

1. Basic Configuration

You can configure the logger using methods of the Logger class. Here is an example of how you can do it:

from gamuLogger import Logger, LEVELS, SENSITIVE_LEVELS

# default target is the standard output, name is 'stdout'

Logger.setLevel("stdout", LEVELS.INFO); # this mean yhat all logs with level less than INFO will be ignored

Logger.setSensitiveLevel("stdout", SENSITIVE_LEVELS.HIDE); # If a log message contains sensitive data, it will be hidden

Logger.addSensitiveData('myPasswordSecret'); # add 'myPasswordSecret' to the list of sensitive data (if a log message contains any of them, it will be hidden according to the sensitive level)

Logger.setModule('my-module'); # set the module name for this file to 'my-module' (this will be displayed in the log message) (by default, no module name is set)

Logger.addTarget("data.log", LEVELS.DEBUG, SENSITIVE_LEVELS.HIDE) # add a new target to the logger (this will log all messages with level less than DEBUG to the file 'data.log' and hide sensitive data if any)

Please note that the logger can be used without any manual configuration. The default configuration is:

  • target: terminal
    • level: INFO
    • sensitive mode: HIDE
  • sensitive data: []
  • module name: None

Note that the module name is set only for the current file. If you want to set the module name for all files, you need to set it in each file.

2. Configuration with argparse

This module is compatible with argparse, and contains confugurations methods for the argument parser:

from gamuLogger import Logger
import argparse

parser = argparse.ArgumentParser()
Logger.configArgParse(parser) # this will add options to the parser, encapsulated in a group named 'Logger configuration'
args = parser.parse_args()
Logger.parseArgs(args) # this will apply the configuration from the arguments to the logger

3. Configuration from a file

3.1. JSON Configuration

3.2. XML Configuration

📁 Examples

you can find examples in the example directory.

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

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

gamulogger-2.1.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

gamuLogger-2.1.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file gamulogger-2.1.1.tar.gz.

File metadata

  • Download URL: gamulogger-2.1.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for gamulogger-2.1.1.tar.gz
Algorithm Hash digest
SHA256 fcab400769d31938f492ebfc91ca156b4e19c1d253f71075c531fe82b828ad46
MD5 aff63b7ce6f6e9836b1524d5289c9c8a
BLAKE2b-256 66fb509011adcf86b52cf8007a58f7735d94564ddaab0e88258a1144fe069d00

See more details on using hashes here.

File details

Details for the file gamuLogger-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: gamuLogger-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for gamuLogger-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 25bb862254304649a4e1c6d906193e10c35548bebfe6b9abdfa78bdba0c07af5
MD5 6a5dcdb3a108ef3d9fa2e2fabc681bb3
BLAKE2b-256 91a73ba1e0147fb4f6a7884816ee381a81022ec48278fb4478f067313d99f529

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page