diff --git a/logging_json/README.rst b/logging_json/README.rst index 4d60884d9..fcf2f9dea 100644 --- a/logging_json/README.rst +++ b/logging_json/README.rst @@ -1,10 +1,16 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============== 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``. @@ -12,3 +18,54 @@ The json logging is activated with the environment variable 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. +To configure this module, you need to: + +Known issues / Roadmap +====================== + +* Completed the extraction (in regex) of interesting message to get more metric + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Guewen Baconnier +* Sébastien BEAU + +Funders +------- + +The development of this module has been financially supported by: + +* Camptocamp +* Akretion + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/logging_json/__openerp__.py b/logging_json/__openerp__.py index e73ded244..b8b0af2e8 100644 --- a/logging_json/__openerp__.py +++ b/logging_json/__openerp__.py @@ -4,7 +4,7 @@ {'name': 'JSON Logging', 'version': '9.0.1.0.0', - 'author': 'Camptocamp,Odoo Community Association (OCA)', + 'author': 'Camptocamp,Akretion,Odoo Community Association (OCA)', 'license': 'AGPL-3', 'category': 'Extra Tools', 'depends': ['base', diff --git a/logging_json/json_log.py b/logging_json/json_log.py index 3fcc7968e..1810c383e 100644 --- a/logging_json/json_log.py +++ b/logging_json/json_log.py @@ -1,8 +1,14 @@ # -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp (http://www.camptocamp.com). +# @author Guewen Baconnier +# Copyright 2017 Akretion (http://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging import os import threading +import re from distutils.util import strtobool @@ -18,6 +24,34 @@ except ImportError: def is_true(strval): return bool(strtobool(strval or '0'.lower())) +# The following regex are use to extract information from native odoo log +# We struct is the following +# {name_of_the_log : [regex, formatter, extra_vals]} +# The extra_vals "dict" will be merged into the jsonlogger if the regex match +# In order to make understandable the regex please add an string example that +# match + +REGEX = { + 'openerp.addons.base.ir.ir_cron': [ + # "cron.object.execute('db', 1, '*', u'base.action.rule', u'_check')" + ("cron\.object\.execute\('.+'(?P[\w.]+).+" + "'(?P[\w.]+)'\)", + {}, {'cron_running': True}), + + # "0.016s (base.action.rule, _check)" + ("(?P[\d.]+)s \(" + "(?P[\w.]+), (?P[\w.]+)", + {'cron_duration_second': float}, + {'cron_running': False, 'cron_status': 'succeeded'}), + + # Call of self.pool.get('base.action.rule')._check( + # cr, uid, *u'()') failed in Job 43 + ("Call of self\.pool\.get\('(?P[\w.]+)'\)" + ".(?P[\w.]+)", + {}, {'cron_running': False, 'cron_status': 'failed'}), + ], +} + class OdooJsonFormatter(jsonlogger.JsonFormatter): @@ -25,7 +59,18 @@ class OdooJsonFormatter(jsonlogger.JsonFormatter): record.pid = os.getpid() record.dbname = getattr(threading.currentThread(), 'dbname', '?') _super = super(OdooJsonFormatter, self) - return _super.add_fields(log_record, record, message_dict) + res = _super.add_fields(log_record, record, message_dict) + if log_record['name'] in REGEX: + for regex, formatters, extra_vals in REGEX[log_record['name']]: + match = re.match(regex, log_record['message']) + if match: + vals = match.groupdict() + for key, func in formatters.items(): + vals[key] = func(vals[key]) + log_record.update(vals) + if extra_vals: + log_record.update(extra_vals) + return res if is_true(os.environ.get('ODOO_LOGGING_JSON')):