mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
Add logging_json
Output odoo logs as json
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
JSON Logging
|
||||
============
|
||||
|
||||
This addon allows to output the Odoo logs in JSON.
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The json logging is activated with the environment variable
|
||||
``ODOO_LOGGING_JSON`` set to ``1``.
|
||||
|
||||
In order to have the logs from the start of the server, you should add
|
||||
``logging_json`` in the ``--load`` flag or in the ``server_wide_modules``
|
||||
option in the configuration file.
|
||||
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import json_log
|
||||
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
{'name': 'JSON Logging',
|
||||
'version': '9.0.1.0.0',
|
||||
'author': 'Camptocamp',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Extra Tools',
|
||||
'depends': ['base',
|
||||
],
|
||||
'external_dependencies': {
|
||||
'python': ['pythonjsonlogger'],
|
||||
},
|
||||
'website': 'http://www.camptocamp.com',
|
||||
'data': [],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
|
||||
from distutils.util import strtobool
|
||||
|
||||
from pythonjsonlogger import jsonlogger
|
||||
|
||||
|
||||
def is_true(strval):
|
||||
return bool(strtobool(strval or '0'.lower()))
|
||||
|
||||
|
||||
class OdooJsonFormatter(jsonlogger.JsonFormatter):
|
||||
|
||||
def add_fields(self, log_record, record, message_dict):
|
||||
record.pid = os.getpid()
|
||||
record.dbname = getattr(threading.currentThread(), 'dbname', '?')
|
||||
_super = super(OdooJsonFormatter, self)
|
||||
return _super.add_fields(log_record, record, message_dict)
|
||||
|
||||
|
||||
if is_true(os.environ.get('ODOO_LOGGING_JSON')):
|
||||
format = ('%(asctime)s %(pid)s %(levelname)s'
|
||||
'%(dbname)s %(name)s: %(message)s')
|
||||
formatter = OdooJsonFormatter(format)
|
||||
logging.getLogger().handlers[0].formatter = formatter
|
||||
Reference in New Issue
Block a user