loggerk


Nameloggerk JSON
Version 0.0.5 PyPI version JSON
download
home_pageNone
SummaryThis is a custom logger module for Python
upload_time2024-04-26 15:49:22
maintainerAngel de Jesús Sanchez Morales
docs_urlNone
authorKuantik DataJump
requires_pythonNone
licenseNone
keywords python logging
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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 sent in the authorization header of the log request.


## Usage
Import LoggerK from the `loggerk` mdoule 

```python
from loggerk import LoggerK
```

Then initialize the LoggerK class, and call the usual methods

```python
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.


### `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](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema).

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.


### 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:
```python
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:

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "loggerk",
    "maintainer": "Angel de Jes\u00fas Sanchez Morales",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "angel.sanchez@kuantik.mx",
    "keywords": "python, logging",
    "author": "Kuantik DataJump",
    "author_email": "master@kuantik.mx",
    "download_url": "https://files.pythonhosted.org/packages/2b/ab/2af33b32af82cd2b45106adbd5c168d22a98159aac41893fa310d13d1467/loggerk-0.0.5.tar.gz",
    "platform": null,
    "description": "# loggerk\nThis is a custom logger module for Python\n\nEnviroment variables required:\n\n- `LOGGER_APP_NAME`: The name of the App\n- `LOGGER_URLS`: a list of URLS to send the log requests to. Separated by commas.\n- `LOGGER_CREDENTIALS`: If needed, the credentials sent in the authorization header of the log request.\n\n\n## Usage\nImport LoggerK from the `loggerk` mdoule \n\n```python\nfrom loggerk import LoggerK\n```\n\nThen initialize the LoggerK class, and call the usual methods\n\n```python\nlogger = LoggerK(__name__)\n\nlogger.debug(\"This is a debug level message.\")\nlogger.info(\"This is an info level message\")\nlogger.warning(\"This is a warning level message\")\nlogger.error(\"This is an error level message\")\nlogger.critical(\"This is a critical level message\")\n```\n\nThe `LoggerK` initializer takes several arguments:\n\n* `name: str` \n* `app_name: str`\n* `level: str | int`\n* `config: ConfigDict`\n* `file_path: str`\n\nThe only required argument is `name`. The rest of the arguments are Optional.\n\n\n### `app_name`\n\nRepresents 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`.\n\n### `level`\n\nIs 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:\n\n- `\"DEBUG\"`\n- `\"INFO\"`\n- `\"WARNING\"`\n- `\"ERROR\"`\n- `\"CRITICAL\"`\n\nWhen using handlers, if the handler does not define a logging level, this default level will be used.\n\n### `config`\n\nA dictionary containing the configuration for the logger.\n\nFor more info on how to configure the logger check the [logging.config Logging configuration](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema).\n\nThe `LoggerK` initializer has a `DEFAULT_CONFIG` dictionary which includes three default handlers:\n\n- An `StreamingHandler` to the standar output.\n- A `RotatingFileHandler` that defaults to `\"logs/app.log\"`\n- 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.\n\n### `file_path`\n\nWhen given a value, will override every FileHandler inside the `config` dictionary.\n\n\n### Note:\nInitializing 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.\n\n#### Example:\n```python\nlogger_1 = LoggerK(\"my_new_logger\")\n\nlogger_2 = LoggerK(\n    \"my_new_logger\", \n    config=SOME_CUSTOM_CONFIG,\n)\n\n# The new config on logger_2 will apply also for the logger_1 as they share the same name.\n```\n\n## Configuring the log instance\n\nIf needed, the log instance can be configured after initialization by updating the `ConfigDict` in the  `Loggerk.config` attribute.\n\n#### Example:\n\n```python\nlogger = LoggerK(__name__)\n\ncurrent_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.\n\n# updating the configuration\nnew_config = current_configuration[\"handlers\"][\"file\"][\"level\"] = \"ERROR\" #changing the debug level of the file handler\n\n# setting the new configuration to the logger instance\nlogger.config = new_configuration\n```\n\nEvery time the value of `config` is set, the instance will be reconfigured, so all new configurations are applied.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This is a custom logger module for Python",
    "version": "0.0.5",
    "project_urls": null,
    "split_keywords": [
        "python",
        " logging"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7bc5dc83fec5225f4bff11495720c0b505fed32ba1483926bd7d4093a831337",
                "md5": "6c408a7192a00ae3346bc035282ca424",
                "sha256": "d8e9f9b74d66cdcedc2f526bbe3a7bcbbaaff2829db6dc63ab6f19af8f772f62"
            },
            "downloads": -1,
            "filename": "loggerk-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6c408a7192a00ae3346bc035282ca424",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10484,
            "upload_time": "2024-04-26T15:49:21",
            "upload_time_iso_8601": "2024-04-26T15:49:21.780074Z",
            "url": "https://files.pythonhosted.org/packages/f7/bc/5dc83fec5225f4bff11495720c0b505fed32ba1483926bd7d4093a831337/loggerk-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2bab2af33b32af82cd2b45106adbd5c168d22a98159aac41893fa310d13d1467",
                "md5": "87bfd3e51fa7d436856860871d42f9d6",
                "sha256": "fdfe69d7b4b31579bb25785f65a821f85b6e3e897f31776ba0a0cae69efe7599"
            },
            "downloads": -1,
            "filename": "loggerk-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "87bfd3e51fa7d436856860871d42f9d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10950,
            "upload_time": "2024-04-26T15:49:22",
            "upload_time_iso_8601": "2024-04-26T15:49:22.828580Z",
            "url": "https://files.pythonhosted.org/packages/2b/ab/2af33b32af82cd2b45106adbd5c168d22a98159aac41893fa310d13d1467/loggerk-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-26 15:49:22",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "loggerk"
}
        
Elapsed time: 0.24518s