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 AppLOGGER_URLS: a list of URLS to send the log requests to. Separated by commas.LOGGER_CREDENTIALS: If needed, the credentials sent in the authorization header of the log request.
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: strapp_name: strlevel: str | intconfig: ConfigDictfile_path: str
The only required argument is name. The rest of the arguments are Optional.
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
StreamingHandlerto the standar output. - A
RotatingFileHandlerthat defaults to"logs/app.log" - A
CustomHttpHandlerthat will make a post request for every log message to the first URL that returns a succesful response within the given URLs in theLOGGER_URLSenv variable.
file_path
When given a value, will override every FileHandler inside the config dictionary.
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.
Configuring the log instance
If needed, the log instance can be configured after initialization by updating the ConfigDict in the Loggerk.config attribute.
Example:
logger = LoggerK(__name__)
current_config = logger.config # accessing the current configuration of the looger instance. This returns a copy of the config dictionary, so updating directly will have no efect on the actual configuration of the logger instance.
# updating the configuration
new_config = current_configuration["handlers"]["file"]["level"] = "ERROR" #changing the debug level of the file handler
# setting the new configuration to the logger instance
logger.config = new_configuration
Every time the value of config is set, the instance will be reconfigured, so all new configurations are applied.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loggerk-0.0.6.tar.gz.
File metadata
- Download URL: loggerk-0.0.6.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac4ebd806f94831c04bca8741e2ed99c0ea91c35adab1352747cfa2754d5cfcb
|
|
| MD5 |
46adfb3293980eae7e7cb4dfc736b8ae
|
|
| BLAKE2b-256 |
a4793fdfa3cfda42470b05eb650c87b0f05f70124ac2617af08243c0ab795113
|
File details
Details for the file loggerk-0.0.6-py3-none-any.whl.
File metadata
- Download URL: loggerk-0.0.6-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a90e7655dd8a5742f34520d0514e4dad74f636ec61a23b61bda0bec08f9057e9
|
|
| MD5 |
f23fd00b23572629bb8f27fec886667f
|
|
| BLAKE2b-256 |
6b26c55a00fe54aa4d6f1c8a77545015d2294980e97f15a88599824eaa58f646
|