json-logger-stdout


Namejson-logger-stdout JSON
Version 1.1.4 PyPI version JSON
download
home_pagehttps://gitlab.com/chalukyaj/json-logger-stdout
SummaryJSON Logger for MicroServices. Prints logs to the stdout of the service and can be shipped to ES by leveraging a centralized tool like Fluentd.
upload_time2023-03-17 16:38:57
maintainer
docs_urlNone
authorChalukya J
requires_python>=3.6,<4.0
licenseMIT
keywords json-logger micro-services containers docker kubernetes fluetd stdout
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # JSON Logger Stdout
##### Log to the stdout directly so that they can be consumed by some centralized log collecting service like Fluentd.
=================================================================================================

JSON Logger for MicroServices. Prints logs to the stdout of the service and can be shipped to ES by leveraging a centralized tool like Fluentd
> Usage Examples
`json_std_logger` is the log object that the library exports and it exposes methods for all log levels which is shown in the examples. This is an instance of the class `JSONLoggerStdout`

> Important Note: By default the log level is set at `INFO`. Please change it using the `setLevel` method which is exposed out.


```bash
from json_logger_stdout import JSONStdFormatter, json_std_logger

#By Default the log level is INFO

json_std_logger.error('error log')      # {"timestamp": "2022-01-21T06:36:32.668292Z", "level": "ERROR", "message": "error log"}
json_std_logger.info('info log')        # {"timestamp": "2022-01-21T06:36:32.668420Z", "level": "INFO", "message": "info log"}
json_std_logger.debug('debug log, no print')      # Prints Nothing as the current level by default is INFO

import logging
json_std_logger.setLevel(logging.DEBUG) # Set Log Level
json_std_logger.debug('debug log')      # {"timestamp": "2022-01-21T06:36:32.668476Z", "level": "DEBUG", "message": "debug log"}

```

### List of Exposed Methods
`getLogger` : Returns the already initialized log object.

`setLevel` : Sets Log Level. Pass any valid log level from the python `logging` module.

`setFormatter` : Sets a custom log formatter if needed. This call will clear out all the other handlers, so please call this before adding more log handlers. It takes two arguments, the first one is simply a string that takes the fields to print in the final log. See `#Example-Set-Formatter-1` for more details.
It is possible to use a different log formatter altogether and use the second parameter to pass the log formatter object. See `#Example-Set-Formatter-2` for more details.

`addHandlers` : Pass an array of log handlers that will be attached to the log object.

### Extra Params for the logger instance
You can also configure permanent extra params to be used for a log object if you prefer not to mention it everytime in your log messages. You can either pass the params in during initializing a new `JSONLoggerStdout` instance or adding them using the `_setParams` method in the `json_std_logger`.
```bash
from json_logger_stdout import JSONLoggerStdout
logger = JSONLoggerStdout(
    service="Running Service",
    id="CAT-232"
)
logger.error('error log')          # {"timestamp": "2023-03-17T16:11:32.858440Z", "level": "ERROR", "message": "error log", "service": "Running Service", "id": "CAT-232"}
```
```bash
from json_logger_stdout import json_std_logger
json_std_logger._setParams(
    service="Different Service",
    id="ASD-233"
)
json_std_logger.info('info log')            # {"timestamp": "2023-03-17T16:11:32.858540Z", "level": "INFO", "message": "info log", "service": "Different Service", "id": "ASD-233"}
```

### Advanced Usage
The package exposes two classes `JSONLoggerStdout` & `JSONStdFormatter`
It is possible for the user to get a different log object by using the base class `JSONLoggerStdout`
```
json_logger = JSONLoggerStdout(loggerName=<optional>)
```

> NOTE : All the unnamed parameters that are passed to the logger would be converted to string and concatenated with a space ` `.
However sending named parameters to the logger would add the keys as extra parameters in the log record. Please see the last example for more clarity on this.
```bash
json_std_logger.setFormatter('%(timestamp)s %(level)s %(name) %(filename)s %(lineno)s %(module)s %(message)s')     # Example-Set-Formatter-1
json_std_logger.setFormatter(None, JSONStdFormatter('%(timestamp)s %(level)s %(name) %(filename)s %(lineno)s %(message)s'))   # Example-Set-Formatter-2

# Usage with variable parameters and named parameters to the logger.
json_std_logger.debug({'unnamedObjKey1': 'will print in message'}, {'unnamedObjKey2': 'should be concatenated with the previous part'}, extra='Named Parameter, so will be addded as an extra parameter')
# {"timestamp": "2022-01-21T07:40:03.363500Z", "level": "DEBUG", "name": "root", "filename": "json_logger_stdout.py", "lineno": 67, "module": "json_logger_stdout", "message": "{'unnamedObjKey1': 'will print in message'}, {'unnamedObjKey2': 'should be concatenated with the previous part'}", "extra": "Named Parameter, so will be addded as an extra parameter"}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/chalukyaj/json-logger-stdout",
    "name": "json-logger-stdout",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6,<4.0",
    "maintainer_email": "",
    "keywords": "json-logger,micro-services,containers,docker,kubernetes,fluetd,stdout",
    "author": "Chalukya J",
    "author_email": "chalukyaj@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/12/39/93e95ec11ae132efb2cae37fcd0ce62debeac1f962ae214d4dcdaf7cf44f/json_logger_stdout-1.1.4.tar.gz",
    "platform": null,
    "description": "# JSON Logger Stdout\n##### Log to the stdout directly so that they can be consumed by some centralized log collecting service like Fluentd.\n=================================================================================================\n\nJSON Logger for MicroServices. Prints logs to the stdout of the service and can be shipped to ES by leveraging a centralized tool like Fluentd\n> Usage Examples\n`json_std_logger` is the log object that the library exports and it exposes methods for all log levels which is shown in the examples. This is an instance of the class `JSONLoggerStdout`\n\n> Important Note: By default the log level is set at `INFO`. Please change it using the `setLevel` method which is exposed out.\n\n\n```bash\nfrom json_logger_stdout import JSONStdFormatter, json_std_logger\n\n#By Default the log level is INFO\n\njson_std_logger.error('error log')      # {\"timestamp\": \"2022-01-21T06:36:32.668292Z\", \"level\": \"ERROR\", \"message\": \"error log\"}\njson_std_logger.info('info log')        # {\"timestamp\": \"2022-01-21T06:36:32.668420Z\", \"level\": \"INFO\", \"message\": \"info log\"}\njson_std_logger.debug('debug log, no print')      # Prints Nothing as the current level by default is INFO\n\nimport logging\njson_std_logger.setLevel(logging.DEBUG) # Set Log Level\njson_std_logger.debug('debug log')      # {\"timestamp\": \"2022-01-21T06:36:32.668476Z\", \"level\": \"DEBUG\", \"message\": \"debug log\"}\n\n```\n\n### List of Exposed Methods\n`getLogger` : Returns the already initialized log object.\n\n`setLevel` : Sets Log Level. Pass any valid log level from the python `logging` module.\n\n`setFormatter` : Sets a custom log formatter if needed. This call will clear out all the other handlers, so please call this before adding more log handlers. It takes two arguments, the first one is simply a string that takes the fields to print in the final log. See `#Example-Set-Formatter-1` for more details.\nIt is possible to use a different log formatter altogether and use the second parameter to pass the log formatter object. See `#Example-Set-Formatter-2` for more details.\n\n`addHandlers` : Pass an array of log handlers that will be attached to the log object.\n\n### Extra Params for the logger instance\nYou can also configure permanent extra params to be used for a log object if you prefer not to mention it everytime in your log messages. You can either pass the params in during initializing a new `JSONLoggerStdout` instance or adding them using the `_setParams` method in the `json_std_logger`.\n```bash\nfrom json_logger_stdout import JSONLoggerStdout\nlogger = JSONLoggerStdout(\n    service=\"Running Service\",\n    id=\"CAT-232\"\n)\nlogger.error('error log')          # {\"timestamp\": \"2023-03-17T16:11:32.858440Z\", \"level\": \"ERROR\", \"message\": \"error log\", \"service\": \"Running Service\", \"id\": \"CAT-232\"}\n```\n```bash\nfrom json_logger_stdout import json_std_logger\njson_std_logger._setParams(\n    service=\"Different Service\",\n    id=\"ASD-233\"\n)\njson_std_logger.info('info log')            # {\"timestamp\": \"2023-03-17T16:11:32.858540Z\", \"level\": \"INFO\", \"message\": \"info log\", \"service\": \"Different Service\", \"id\": \"ASD-233\"}\n```\n\n### Advanced Usage\nThe package exposes two classes `JSONLoggerStdout` & `JSONStdFormatter`\nIt is possible for the user to get a different log object by using the base class `JSONLoggerStdout`\n```\njson_logger = JSONLoggerStdout(loggerName=<optional>)\n```\n\n> NOTE : All the unnamed parameters that are passed to the logger would be converted to string and concatenated with a space ` `.\nHowever sending named parameters to the logger would add the keys as extra parameters in the log record. Please see the last example for more clarity on this.\n```bash\njson_std_logger.setFormatter('%(timestamp)s %(level)s %(name) %(filename)s %(lineno)s %(module)s %(message)s')     # Example-Set-Formatter-1\njson_std_logger.setFormatter(None, JSONStdFormatter('%(timestamp)s %(level)s %(name) %(filename)s %(lineno)s %(message)s'))   # Example-Set-Formatter-2\n\n# Usage with variable parameters and named parameters to the logger.\njson_std_logger.debug({'unnamedObjKey1': 'will print in message'}, {'unnamedObjKey2': 'should be concatenated with the previous part'}, extra='Named Parameter, so will be addded as an extra parameter')\n# {\"timestamp\": \"2022-01-21T07:40:03.363500Z\", \"level\": \"DEBUG\", \"name\": \"root\", \"filename\": \"json_logger_stdout.py\", \"lineno\": 67, \"module\": \"json_logger_stdout\", \"message\": \"{'unnamedObjKey1': 'will print in message'}, {'unnamedObjKey2': 'should be concatenated with the previous part'}\", \"extra\": \"Named Parameter, so will be addded as an extra parameter\"}\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "JSON Logger for MicroServices. Prints logs to the stdout of the service and can be shipped to ES by leveraging a centralized tool like Fluentd.",
    "version": "1.1.4",
    "split_keywords": [
        "json-logger",
        "micro-services",
        "containers",
        "docker",
        "kubernetes",
        "fluetd",
        "stdout"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aa7849adb1a5ae2591b38e0ac788e1ca444b9ba52f66f3dc25e08175a5366866",
                "md5": "8b17ee25633bd8908bf77c451f871c8e",
                "sha256": "d71f668c0556744cfc36d1f303511e43479ceb89fde0b5d28aa41e962485260b"
            },
            "downloads": -1,
            "filename": "json_logger_stdout-1.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b17ee25633bd8908bf77c451f871c8e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6,<4.0",
            "size": 4071,
            "upload_time": "2023-03-17T16:38:56",
            "upload_time_iso_8601": "2023-03-17T16:38:56.644222Z",
            "url": "https://files.pythonhosted.org/packages/aa/78/49adb1a5ae2591b38e0ac788e1ca444b9ba52f66f3dc25e08175a5366866/json_logger_stdout-1.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "123993e95ec11ae132efb2cae37fcd0ce62debeac1f962ae214d4dcdaf7cf44f",
                "md5": "f7472d6176c7df3f7ff79c40248bb8ff",
                "sha256": "4d34b4df92e2ad499748340787f1b279863018a92e907a9f575a3f97dd1a54eb"
            },
            "downloads": -1,
            "filename": "json_logger_stdout-1.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "f7472d6176c7df3f7ff79c40248bb8ff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6,<4.0",
            "size": 3509,
            "upload_time": "2023-03-17T16:38:57",
            "upload_time_iso_8601": "2023-03-17T16:38:57.727004Z",
            "url": "https://files.pythonhosted.org/packages/12/39/93e95ec11ae132efb2cae37fcd0ce62debeac1f962ae214d4dcdaf7cf44f/json_logger_stdout-1.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-17 16:38:57",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "gitlab_user": "chalukyaj",
    "gitlab_project": "json-logger-stdout",
    "lcname": "json-logger-stdout"
}
        
Elapsed time: 0.04967s