Skip to main content

This is a custom logger module for Python

Project description

loggerk

This is a custom logger module for Python

Enviroment variables required:

  • LOGGER_APP_NAME: The name of the App
  • LOGGER_URLS: a list of URLS to send the log requests to. Separated by commas.
  • LOGGER_CREDENTIALS: If needed, the credentials to send the log resuests with.

Usage

Import LoggerK from the loggerk mdoule

from loggerk import LoggerK

Then initialize the LoggerK class, and call the usual methods

logger = LoggerK(__name__)

logger.debug("This is a debug level message.")
logger.info("This is an info level message")
logger.warning("This is a warning level message")
logger.error("This is an error level message")
logger.critical("This is a critical level message")

The LoggerK initializer takes several arguments:

  • name: str
  • app_name: str
  • level: str | int
  • config: ConfigDict
  • file_path: str

The only required argument is name. The rest of the arguments are Optional.

Note:

Initializing two LoggerK instances with the same name will behave as a Singleton, so any new configuration to the new instance will affect all existing instances with the same name.

Example:

logger_1 = LoggerK("my_new_logger")

logger_2 = LoggerK(
    "my_new_logger", 
    config=SOME_CUSTOM_CONFIG,
)

# The new config on logger_2 will apply also for the logger_1 as they share the same name.

app_name

Represents the name of the application in which the logger instance is being created. If it is not provided, it will be extracted from the environment as LOGGER_APP_NAME.

level

Is the default level for the logger, it can take integer values, however its recommended for better readability to use the Literal values defined in the class:

  • "DEBUG"
  • "INFO"
  • "WARNING"
  • "ERROR"
  • "CRITICAL"

When using handlers, if the handler does not define a logging level, this default level will be used.

config

A dictionary containing the configuration for the logger.

For more info on how to configure the logger check the logging.config Logging configuration.

The LoggerK initializer has a DEFAULT_CONFIG dictionary which includes three default handlers:

  • An StreamingHandler to the standar output.
  • A RotatingFileHandler that defaults to "logs/app.log"
  • A CustomHttpHandler that will make a post request for every log message to the first URL that returns a succesful response within the given URLs in the LOGGER_URLS env variable.

file_path

When given a value, will override every FileHandler inside the config dictionary.

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

loggerk-0.0.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

loggerk-0.0.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file loggerk-0.0.1.tar.gz.

File metadata

  • Download URL: loggerk-0.0.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for loggerk-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7825028f6c22a2ab4377957212b0bcb25e2033bfaae0551119ce2d20b575ba95
MD5 63f425bd4b0c6a905d1d8b7cd6a36650
BLAKE2b-256 08660ed0d02ff07bd944ff272666b24860987e0d7b003b8ee1b7459a639940d9

See more details on using hashes here.

File details

Details for the file loggerk-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: loggerk-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for loggerk-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 acf5fc44d666d044199ac89d20e40ba78e2137b94c8780968cf4f8e045309620
MD5 01c682b49dc32bcbc05bb99de5609b14
BLAKE2b-256 d8170b4c823c2e40e87a977d952b1df93551776d51701f9e42621b71798d7b18

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