jsonloggeriso8601datetime


Namejsonloggeriso8601datetime JSON
Version 1.0.5 PyPI version JSON
download
home_pagehttps://github.com/joeldodson/jsonloggeriso8601datetime
SummaryCustom formatter for python-json-logger to iso8601 format timestamps. includes default console and file logger config
upload_time2024-06-24 22:22:31
maintainerBlindGumption
docs_urlNone
authorJoel Dodson
requires_python<4.0,>=3.10
licenseMIT
keywords structured console logging json iso8601 configuration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # jsonloggeriso8601datetime Package

This package is mainly about providing an out of the box configuration to enable the builtin Python logging package to generate logs as JSON.  
It starts with the package
[python-json-logger](https://pypi.org/project/python-json-logger/) 
and adds a simple custom formatter to format the timestamp to comply with ISO8601 formats.
It also provides a default config to log to the console and to a log file. 
After installing the package, run
``` sh
python -m jsonloggeriso8601datetime --example
```
to see the default console logging output.
And look in ``` logs/jsonLogs.log ``` to see the default file logging output.

If you're happy with the default configuration, the basic use case is all you need.
If you want to change the configuration (e.g., add more properties to the file output, change default logging levels), pass in a modified dict to setConfig().
You can get the default config using:

``` sh 
python -m jsonloggeriso8601datetime -d > myCustomConfig.py
```

edit myConfig.py to give the dict a variable name, then import myConfig, name you gave your dict variable, to your project and use that dict in setConfig. 

For the log file output, the package will ensure the directory exists before trying to write to the log file.
This is done by the MakedirFileHandler class.
Check out the wrappers.py module in jsonloggeriso8601datetime package if you're curious.

## How To Use

Add the below lines to the beginning of the main python file (where __name__ == "__main__"):

``` python
import logging
import jsongloggeriso8601datetime as jlidt
jlidt.setConfig()  # using the provided default configuration 
```

This will configure a root logger which, from my understanding of Python logging, will result in all subsequent logs to use that configuration (unless specifically overridden).

## Configuration

The file jsonloggerdictconfig.py, in the package's directory contains default configuration for logging to stdout with minimal information, not JSON formatted.
It also configures a handler to log to a file with much more information and log statements are JSON formatted.
As noted above, you can see the values of the default configuration by running ``` python -m jsonloggeriso8601datetime -d  ```.
I've created this default configuration with screen readers in mind.
Logging to the console is minimized to avoid a lot of screen reader chatter.
Logging to a file is maximized and formatted to support other tools processing those logs and possibly presenting the information in a more accessible way.
Also, if logs are to be processed by any anomaly detection systems, JSON is probably best.

The log level for both console and JSON file defaults to "INFO".
that can be changed by setting environment variables to the desired level.
For example, in PowerShell:
``` sh
Env:JLIDT_CONSOLE_LEVEL = "DEBUG"
Env:JLIDT_JSONFILE_LEVEL = "WARNING"
```
will set the console logger to DEBUG and the JSON file logger to WARNING.

You might notice there's a gunicorn logger in the config file.
I added that to get gunicorn to work with this default config.
There might be a better way to do this.  I stopped looking for solutions once I got this working with gunicorn.

## Dependencies

The python-json-logger is the only requirement at time of writing.
It's unfortunately going through some possible abandonment issues.
A new maintainer (nhairs) has stepped up and made many fixes.
Unfortunately the current maintainer does not aappear to be responding and merging PRs.
Thus, [python-json-logger is currently being pulled from github](https://github.com/nhairs/python-json-logger).
That repo page has information regarding the process of switching maintainers.

### temporary workaround 

Turns out PyPI does not like people uploading packages with dependencies pointing to github.
To be able to publish this package, I copied pythonjsonlogger source code to 
the src directory in jsonloggeriso8601datetime as jlidt_pjl.
This is a temporary solution and 
I added a README  file in that directory to explain it.
Once ownership of python-json-logger is resolved,
I will delete my local copy of pythonjsonlogger source code.

## Scripts

Some simple functionality is provided directly from `jsonloggeriso8601datetime` itself using `python -m`. Run:

``` sh
python -m jsonloggeriso8601datetime --help
```

to see what is available.
As of v1.0.4, you can pretty print the default config to stdout.
You can also run a simple example to check the default config, to determine if it's sufficient.
As noted above, it's currently set to INFO for both the  console and file loggers and changeable using environment variables.

### jilqs (Json Iso8601 Logger Query Script)

jilqs is installed as a script by default (not as an extra).
I decided to do this for simplicity, 
and the name is bad enough it's unlikely to conflict with anything else on your system.
It's very light weight and uses only standard Python.
Run:

``` sh
 jilqs --help 
```

to see what it does.

## Version History

### 1.0.1

* initial package plus typo fix

### 1.0.2

* moved the repo from github.om/blindgumption to github.com/joeldodson
* changed default log levels to INFO and provided env vars option to set different levels

### 1.0.3

* typo in pyproject and using pip-tools changed requirements.txt 

### 1.0.4

- Significant changes but basic usage for logging is backward compatible
- moved project to poetry 
  (I've been using poetry on other projects and didn't want to go back and remember how to release using hatch).
- moved functionality supported by jlidtexample and jlidtdefaultconfig
  into the module itself.
  See notes above under the Scripts heading.
- introduced jilqs (see note above under Scripts heading)

### 1.0.5

- copied python-json-logger source code into jsonloggeriso8601datetime repo.
  This has been noted in the main README and a README created in the jlidt_pjl source directory.
  I decided to bump the version for this to keep it separate from anything else.

## Wrapping It Up

If you like this functionality and want to extend it, I suggest starting with python-json-logger.
The documentation there is very good and it seems to be a popular package on PyPI.
You're even welcome to take my extension and add it to whatever you do to extend python-json-logger.

I built this package really for my own opinions and added it to PyPI so I could pip install it instead of copying it around to different projects.
Also I can import it to the REPL and easily get logs in a file.

If others like this default config and ISO8601 timestamps, great.
Enjoy the package and feel free to open issues on github.

Cheers!!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/joeldodson/jsonloggeriso8601datetime",
    "name": "jsonloggeriso8601datetime",
    "maintainer": "BlindGumption",
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": "blindgumption@gmail.com",
    "keywords": "structured, console, logging, json, iso8601, configuration",
    "author": "Joel Dodson",
    "author_email": "joeldodson@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8a/a7/0216dd5333fa0a88b23bfbea22e4895d3f222b4e6d3017792f7042957dc6/jsonloggeriso8601datetime-1.0.5.tar.gz",
    "platform": null,
    "description": "# jsonloggeriso8601datetime Package\n\nThis package is mainly about providing an out of the box configuration to enable the builtin Python logging package to generate logs as JSON.  \nIt starts with the package\n[python-json-logger](https://pypi.org/project/python-json-logger/) \nand adds a simple custom formatter to format the timestamp to comply with ISO8601 formats.\nIt also provides a default config to log to the console and to a log file. \nAfter installing the package, run\n``` sh\npython -m jsonloggeriso8601datetime --example\n```\nto see the default console logging output.\nAnd look in ``` logs/jsonLogs.log ``` to see the default file logging output.\n\nIf you're happy with the default configuration, the basic use case is all you need.\nIf you want to change the configuration (e.g., add more properties to the file output, change default logging levels), pass in a modified dict to setConfig().\nYou can get the default config using:\n\n``` sh \npython -m jsonloggeriso8601datetime -d > myCustomConfig.py\n```\n\nedit myConfig.py to give the dict a variable name, then import myConfig, name you gave your dict variable, to your project and use that dict in setConfig. \n\nFor the log file output, the package will ensure the directory exists before trying to write to the log file.\nThis is done by the MakedirFileHandler class.\nCheck out the wrappers.py module in jsonloggeriso8601datetime package if you're curious.\n\n## How To Use\n\nAdd the below lines to the beginning of the main python file (where __name__ == \"__main__\"):\n\n``` python\nimport logging\nimport jsongloggeriso8601datetime as jlidt\njlidt.setConfig()  # using the provided default configuration \n```\n\nThis will configure a root logger which, from my understanding of Python logging, will result in all subsequent logs to use that configuration (unless specifically overridden).\n\n## Configuration\n\nThe file jsonloggerdictconfig.py, in the package's directory contains default configuration for logging to stdout with minimal information, not JSON formatted.\nIt also configures a handler to log to a file with much more information and log statements are JSON formatted.\nAs noted above, you can see the values of the default configuration by running ``` python -m jsonloggeriso8601datetime -d  ```.\nI've created this default configuration with screen readers in mind.\nLogging to the console is minimized to avoid a lot of screen reader chatter.\nLogging to a file is maximized and formatted to support other tools processing those logs and possibly presenting the information in a more accessible way.\nAlso, if logs are to be processed by any anomaly detection systems, JSON is probably best.\n\nThe log level for both console and JSON file defaults to \"INFO\".\nthat can be changed by setting environment variables to the desired level.\nFor example, in PowerShell:\n``` sh\nEnv:JLIDT_CONSOLE_LEVEL = \"DEBUG\"\nEnv:JLIDT_JSONFILE_LEVEL = \"WARNING\"\n```\nwill set the console logger to DEBUG and the JSON file logger to WARNING.\n\nYou might notice there's a gunicorn logger in the config file.\nI added that to get gunicorn to work with this default config.\nThere might be a better way to do this.  I stopped looking for solutions once I got this working with gunicorn.\n\n## Dependencies\n\nThe python-json-logger is the only requirement at time of writing.\nIt's unfortunately going through some possible abandonment issues.\nA new maintainer (nhairs) has stepped up and made many fixes.\nUnfortunately the current maintainer does not aappear to be responding and merging PRs.\nThus, [python-json-logger is currently being pulled from github](https://github.com/nhairs/python-json-logger).\nThat repo page has information regarding the process of switching maintainers.\n\n### temporary workaround \n\nTurns out PyPI does not like people uploading packages with dependencies pointing to github.\nTo be able to publish this package, I copied pythonjsonlogger source code to \nthe src directory in jsonloggeriso8601datetime as jlidt_pjl.\nThis is a temporary solution and \nI added a README  file in that directory to explain it.\nOnce ownership of python-json-logger is resolved,\nI will delete my local copy of pythonjsonlogger source code.\n\n## Scripts\n\nSome simple functionality is provided directly from `jsonloggeriso8601datetime` itself using `python -m`. Run:\n\n``` sh\npython -m jsonloggeriso8601datetime --help\n```\n\nto see what is available.\nAs of v1.0.4, you can pretty print the default config to stdout.\nYou can also run a simple example to check the default config, to determine if it's sufficient.\nAs noted above, it's currently set to INFO for both the  console and file loggers and changeable using environment variables.\n\n### jilqs (Json Iso8601 Logger Query Script)\n\njilqs is installed as a script by default (not as an extra).\nI decided to do this for simplicity, \nand the name is bad enough it's unlikely to conflict with anything else on your system.\nIt's very light weight and uses only standard Python.\nRun:\n\n``` sh\n jilqs --help \n```\n\nto see what it does.\n\n## Version History\n\n### 1.0.1\n\n* initial package plus typo fix\n\n### 1.0.2\n\n* moved the repo from github.om/blindgumption to github.com/joeldodson\n* changed default log levels to INFO and provided env vars option to set different levels\n\n### 1.0.3\n\n* typo in pyproject and using pip-tools changed requirements.txt \n\n### 1.0.4\n\n- Significant changes but basic usage for logging is backward compatible\n- moved project to poetry \n  (I've been using poetry on other projects and didn't want to go back and remember how to release using hatch).\n- moved functionality supported by jlidtexample and jlidtdefaultconfig\n  into the module itself.\n  See notes above under the Scripts heading.\n- introduced jilqs (see note above under Scripts heading)\n\n### 1.0.5\n\n- copied python-json-logger source code into jsonloggeriso8601datetime repo.\n  This has been noted in the main README and a README created in the jlidt_pjl source directory.\n  I decided to bump the version for this to keep it separate from anything else.\n\n## Wrapping It Up\n\nIf you like this functionality and want to extend it, I suggest starting with python-json-logger.\nThe documentation there is very good and it seems to be a popular package on PyPI.\nYou're even welcome to take my extension and add it to whatever you do to extend python-json-logger.\n\nI built this package really for my own opinions and added it to PyPI so I could pip install it instead of copying it around to different projects.\nAlso I can import it to the REPL and easily get logs in a file.\n\nIf others like this default config and ISO8601 timestamps, great.\nEnjoy the package and feel free to open issues on github.\n\nCheers!!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Custom formatter for python-json-logger to iso8601 format timestamps.  includes default console and file logger config",
    "version": "1.0.5",
    "project_urls": {
        "Homepage": "https://github.com/joeldodson/jsonloggeriso8601datetime",
        "Repository": "https://github.com/joeldodson/jsonloggeriso8601datetime"
    },
    "split_keywords": [
        "structured",
        " console",
        " logging",
        " json",
        " iso8601",
        " configuration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98cd26d174b90946e3de9751d064f1ffc463ecb0fb12c93a84dcd0ca526c5d14",
                "md5": "89b00a7b2884a10d6fa8b9c210bb40de",
                "sha256": "9d7035426a281f3d6bd89e3bc48d12ed9a04743f6e685fda83ee3fadf1fcd241"
            },
            "downloads": -1,
            "filename": "jsonloggeriso8601datetime-1.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "89b00a7b2884a10d6fa8b9c210bb40de",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 21902,
            "upload_time": "2024-06-24T22:22:29",
            "upload_time_iso_8601": "2024-06-24T22:22:29.629855Z",
            "url": "https://files.pythonhosted.org/packages/98/cd/26d174b90946e3de9751d064f1ffc463ecb0fb12c93a84dcd0ca526c5d14/jsonloggeriso8601datetime-1.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8aa70216dd5333fa0a88b23bfbea22e4895d3f222b4e6d3017792f7042957dc6",
                "md5": "725dba69f12aa117dad8189753b3ec77",
                "sha256": "57801c39f2a4d36b7276787862a9147395670394f42b629bc885524a5a8da33b"
            },
            "downloads": -1,
            "filename": "jsonloggeriso8601datetime-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "725dba69f12aa117dad8189753b3ec77",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 19320,
            "upload_time": "2024-06-24T22:22:31",
            "upload_time_iso_8601": "2024-06-24T22:22:31.195147Z",
            "url": "https://files.pythonhosted.org/packages/8a/a7/0216dd5333fa0a88b23bfbea22e4895d3f222b4e6d3017792f7042957dc6/jsonloggeriso8601datetime-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-24 22:22:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "joeldodson",
    "github_project": "jsonloggeriso8601datetime",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "jsonloggeriso8601datetime"
}
        
Elapsed time: 0.27991s