Code Monkey home page Code Monkey logo

logging_json's People

Contributors

colin-b avatar doojonio avatar matusvalo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

logging_json's Issues

How to log additional custom fields ?

Hi,

I have been testing out logging_json over the last couple of days.

I am able to generate JSON logs.

I would like to add some custom fields so that they are automatically included in the JSON log without the user having to provide additional information. The value of those fields are either queried via environment variable or in-house modules that have functions to retrieve those information.

Some of those fields are

"airport" - value is a string
"building" - value is an integer
"linear_dimension" - value is an unsigned integer
"weight" - value is a floating point number

Cheers

hmm why does not work encoding in setting?

python version is 3.11.5

my logger setting is here

        logger = logging.getLogger(type(self).__name__)

        # set Log Level
        logger.setLevel(logging.INFO)
        # set Stream Handle
        ch = logging.StreamHandler()
        ch.encoding = 'utf-8'
        ch.setLevel(logging.INFO)
        stream_formatter = logging_json.JSONFormatter(fields={
            "name": "name",
            "level_name": "levelname",
            "thread": "thread",
            "process": "process",
            "response": "response"
        })
        ch.setFormatter(stream_formatter)
        logger.addHandler(ch)
        # set Formatter
        file_formatter = logging_json.JSONFormatter(fields={
            "name": "name",
            "level_name": "levelname",
            "thread": "thread",
            "thread_name": "threadName",
            "process": "process",
            "process_name": "processName"
        })

        # set File Handler

        fh = logging.FileHandler(filename=f"{os.getcwd()}/logs/dummy.log",encoding='utf-8')
        fh.setFormatter(file_formatter)
        fh.setLevel(logging.INFO)
        logger.addHandler(fh)
        return logger

logging.info("테스트")

result is below

{"name": "BaseLogger", "level_name": "INFO", "thread": 139637689555784, "thread_name": "MainThread", "process": 314, "process_name": "SpawnProcess-32", "message": "\uc548\ub155"}

encoding utf-8 does not work

latin and unicode characters issue when dumping json

Hi,
i discovered an issue that prints strings with unicode characters as in this example "\u0451".

To fix it I suggest to add parameter ensure_ascii=False in json.dumps() call at line 99 in logging_json._formatter.py

I hope it will help!

Dict configuration example is broken

Executing dict configuratio example yields following exception:

Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/config.py", line 543, in configure
    formatters[name] = self.configure_formatter(
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/config.py", line 652, in configure_formatter
    if '()' in config:
TypeError: argument of type 'JSONFormatter' is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/matus/test2.py", line 13, in <module>
    logging.config.dictConfig({
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/config.py", line 809, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/config.py", line 546, in configure
    raise ValueError('Unable to configure '
ValueError: Unable to configure formatter 'json'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.