kandi background
Explore Kits

python-json-logger | Json Formatter for the standard python logger

 by   madzak Python Version: v2.0.2 License: BSD-2-Clause

 by   madzak Python Version: v2.0.2 License: BSD-2-Clause

Download this library from

kandi X-RAY | python-json-logger Summary

python-json-logger is a Python library typically used in Logging applications. python-json-logger has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can install using 'pip install python-json-logger' or download it from GitHub, PyPI.
This library is provided to allow standard python logging to output log data as json objects. With JSON we can make our logs more readable by machines and we can stop writing custom parsers for syslog type records.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • python-json-logger has a medium active ecosystem.
  • It has 1179 star(s) with 172 fork(s). There are 21 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 25 open issues and 46 have been closed. On average issues are closed in 467 days. There are 2 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of python-json-logger is v2.0.2
python-json-logger Support
Best in #Python
Average in #Python
python-json-logger Support
Best in #Python
Average in #Python

quality kandi Quality

  • python-json-logger has 0 bugs and 0 code smells.
python-json-logger Quality
Best in #Python
Average in #Python
python-json-logger Quality
Best in #Python
Average in #Python

securitySecurity

  • python-json-logger has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • python-json-logger code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
python-json-logger Security
Best in #Python
Average in #Python
python-json-logger Security
Best in #Python
Average in #Python

license License

  • python-json-logger is licensed under the BSD-2-Clause License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
python-json-logger License
Best in #Python
Average in #Python
python-json-logger License
Best in #Python
Average in #Python

buildReuse

  • python-json-logger releases are available to install and integrate.
  • Deployable package is available in PyPI.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • python-json-logger saves you 135 person hours of effort in developing the same functionality from scratch.
  • It has 351 lines of code, 30 functions and 5 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
python-json-logger Reuse
Best in #Python
Average in #Python
python-json-logger Reuse
Best in #Python
Average in #Python
Top functions reviewed by kandi - BETA

kandi has reviewed python-json-logger and discovered the below as its top functions. This is intended to give you an instant insight into python-json-logger implemented functionality, and help decide if they suit your requirements.

  • Initialize the class .
    • Format a record .
      • Encode obj .
        • Add fields to log record .
          • Merge extra fields into target record .
            • Import a module as a string .
              • Format a datetime object .

                Get all kandi verified functions for this library.

                Get all kandi verified functions for this library.

                python-json-logger Key Features

                [Wesley Tanaka - Structured log files in Python using python-json-logger](https://wtanaka.com/node/8201)

                [Archive](https://web.archive.org/web/20201130054012/https://wtanaka.com/node/8201)

                Overview

                copy iconCopydownload iconDownload
                pip install python-json-logger

                With JSON logs can I merge multiple values under a single key

                copy iconCopydownload iconDownload
                class CustomJsonFormatter(jsonlogger.JsonFormatter):
                    def add_fields(self, log_record, record, message_dict):
                        super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
                
                        custom_msg = f"{record.filename}:{record.funcName}:{record.threadName}"
                        log_record["file"] = custom_msg
                
                formatter = CustomJsonFormatter('%(asctime)s %(levelname)s %(file)s %(message)')
                

                Unable to ssh to master node of Google Cloud Dataproc, but can ssh to Compute Engine VM

                copy iconCopydownload iconDownload
                gcloud compute ssh my_username@mycluster-m
                

                Community Discussions

                Trending Discussions on python-json-logger
                • With JSON logs can I merge multiple values under a single key
                • set log severity on google cloud without using google-cloud-logging library
                • Unable to ssh to master node of Google Cloud Dataproc, but can ssh to Compute Engine VM
                Trending Discussions on python-json-logger

                QUESTION

                With JSON logs can I merge multiple values under a single key

                Asked 2022-Jan-06 at 12:56

                I want to merge multiple values under a single JSON key while logging it to the console.

                Here is a code snippet

                
                import logging
                from pythonjsonlogger import jsonlogger
                
                
                LOG_FORMAT = '%(asctime)s %(levelname)s %(filename)s %(funcName)s %(threadName) %(message)'
                
                logformatter = jsonlogger.JsonFormatter(LOG_FORMAT)
                stdloghandler.setFormatter(logformatter)
                logger.addHandler(stdloghandler)
                
                

                Generated Output:

                {"asctime": "2022-01-06 12:21:03,878", "levelname": "DEBUG", "filename": "xyz.py", "funcName": "abc", "threadName": "MainThread", "message": "..............."}
                

                Expected output:

                I want to merge filename,funcName,threadName under one key

                Something like this

                {"asctime": "2022-01-06 12:21:03,878", "levelname": "DEBUG", "file": "xyz.py:abc:MainThread", "message": "..............."}
                
                "file": "xyz.py:abc:MainThread"
                

                I didn't find any examples which did this nor any documents. Reference: https://pypi.org/project/python-json-logger/

                ANSWER

                Answered 2022-Jan-06 at 12:56

                The documentation you linked here shows how to create a custom format. You can also see the attributes of the LogRecord that is passed in to the function call.

                class CustomJsonFormatter(jsonlogger.JsonFormatter):
                    def add_fields(self, log_record, record, message_dict):
                        super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
                
                        custom_msg = f"{record.filename}:{record.funcName}:{record.threadName}"
                        log_record["file"] = custom_msg
                
                formatter = CustomJsonFormatter('%(asctime)s %(levelname)s %(file)s %(message)')
                

                Source https://stackoverflow.com/questions/70607150

                Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                Vulnerabilities

                No vulnerabilities reported

                Install python-json-logger

                You can install using 'pip install python-json-logger' or download it from GitHub, PyPI.
                You can use python-json-logger like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

                Support

                For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                DOWNLOAD this Library from

                Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                over 430 million Knowledge Items
                Find more libraries
                Reuse Solution Kits and Libraries Curated by Popular Use Cases
                Explore Kits

                Save this library and start creating your kit

                Explore Related Topics

                Share this Page

                share link
                Reuse Pre-built Kits with python-json-logger
                Consider Popular Python Libraries
                Try Top Libraries by madzak
                Compare Python Libraries with Highest Support
                Compare Python Libraries with Highest Quality
                Compare Python Libraries with Highest Security
                Compare Python Libraries with Permissive License
                Compare Python Libraries with Highest Reuse
                Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                over 430 million Knowledge Items
                Find more libraries
                Reuse Solution Kits and Libraries Curated by Popular Use Cases
                Explore Kits

                Save this library and start creating your kit

                • © 2022 Open Weaver Inc.