Use pygogo to get the log in json.

import pygogo as gogo
formatter = gogo.formatters.structured_formatter
logger = gogo.Gogo('struct', low_formatter=formatter).get_logger(foo="barbar")

logger.debug('bought', extra={"type": "apple", "price": 250, "color": "red"})
#=> {"name": "struct.base", "level": "DEBUG", "color": "red", "price": 250, "msecs": 587.5449180603027, "time": "2016-01-25 16:02:24", "message": "bought", "foo": "barbar", "type": "apple"}

logger.debug('bought', extra={"type": "PC", "price": 100000, "memory": "16GB"})
#=>{"name": "struct.base", "level": "DEBUG", "price": 100000, "memory": "16GB", "msecs": 587.9619121551514, "time": "2016-01-25 16:02:24", "message": "bought", "foo": "barbar", "type": "PC"}

It seems that output control can be done by passing low_level as an argument of the constructor.

import pygogo as gogo
formatter = gogo.formatters.structured_formatter
logger = gogo.Gogo('struct', low_formatter=formatter, low_level='info').get_logger(foo="barbar")

logger.debug('bought', extra={"type": "apple", "price": 250, "color": "red"})
#=>Does not appear
logger.info('bought', extra={"type": "PC", "price": 100000, "memory": "16GB"})
#=>Get out

Recommended Posts

Use pygogo to get the log in json.
How to use the C library in Python
Log in to the remote server with SSH
Use the MediaWiki API to get Wiki information
How to get the files in the [Python] folder
Create a command to get the work log
Use os.getenv to get environment variables in Python
Use the Java SDK of GoogleMapsAPI to get the result of reverse GeoCoding in Japanese.
How to get the variable name itself in python
How to get the number of digits in Python
How to use the exists clause in Django's queryset
How to use the model learned in Lobe in Python
I want to use the R dataset in python
How to use the generator
How to use the decorator
One liner to get the nth commit hash in Git
How to use the __call__ method in a Python class
How to get the last (last) value in a list in Python
How to get all the keys and values in the dictionary
I can't log in to the admin page with Django3
Notes on how to use marshmallow in the schema library
[Shell] How to get the remote default branch in Git
Programming to fight in the world ~ 5-1
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
How to use the zip function
How to use classes in Theano
Mock in python-how to use mox
Get the desktop path in Python
How to use SQLite in Python
Programming to fight in the world-Chapter 4
Get the script path in Python
In the python command python points to python3.8
How to get the Python version
How to use Mysql in python
How to use ChemSpider in Python
How to use PubChem in Python
Get the desktop path in Python
Cython to try in the shortest
Get the host name in Python
How to use the ConfigParser module
How to log in to Docker + NGINX
Programming to fight in the world ~ 5-2
Get the query string (query string) in Django
Automatically acquire the operation log in the terminal when logging in to Linux
How to get all the possible values in a regular expression
Use PyCaret to predict the price of pre-owned apartments in Tokyo!
How to use the asterisk (*) in Python. Maybe this is all? ..
[Introduction to Python] How to use the in operator in a for statement?
The easiest way to get started in Slack socket mode (Go)
What to do if you can't use the trash in Lubuntu 18.04.
Create a function to get the contents of the database in Go
How to use the render function defined in .mako (.html) directly in mako
Format the Git log and get the committed file name in csv format
Get the IPv4 address assigned to the network interface in code (Linux)
How to use calculated columns in CASTable
Use the type features evolved in Sphinx-2.4
Get the client's IP address in Django
[Introduction to Python] How to use class in Python?
How to use Google Test in C
How to get the date and time difference in seconds with python