Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions auditlog_stdout/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==================================
Auditlog - option to log to STDOUT
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e032c4b4bd3b8ecdc8a8f7369e904d48db358d43586f117475d611475b5149eb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/18.0/auditlog_stdout
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-auditlog_stdout
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Add an option to an auditlog rule to output a log to Odoo's logger
instead of creating auditlog.log and auditlog.log.line records.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20auditlog_stdout%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Contributors
------------

- Antonio Buric <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/auditlog_stdout>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions auditlog_stdout/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions auditlog_stdout/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Auditlog - option to log to STDOUT",
"version": "18.0.1.0.0",
"author": "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools",
"license": "AGPL-3",
"category": "Tools",
"summary": "Allows to extend an auditlog rule to output to STDOUT.",
"depends": [
"auditlog",
],
"data": [
"views/auditlog_rule_view.xml",
],
"installable": True,
}
25 changes: 25 additions & 0 deletions auditlog_stdout/i18n/auditlog_stdout.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * auditlog_stdout
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 18.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: auditlog_stdout
#: model:ir.model.fields,help:auditlog_stdout.field_ir_model_fields__stdout
msgid "If set, the log entries will be only logged to STDOUT "
"(rather than creating an auditlog log and line entries)."
msgstr ""

#. module: auditlog_stdout
#: model:ir.model.fields,field_description:auditlog_stdout.field_ir_model_fields__stdout
msgid "Output to STDOUT"
msgstr ""
2 changes: 2 additions & 0 deletions auditlog_stdout/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import auditlog_log
from . import auditlog_rule
54 changes: 54 additions & 0 deletions auditlog_stdout/models/auditlog_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import json
import logging
from collections import defaultdict

from odoo import api, models

_logger = logging.getLogger(__name__)


class AuditlogLog(models.Model):
_inherit = "auditlog.log"

@api.model_create_multi
def create(self, vals_list):
"""Handle auditlog output to STDOUT, rather than creating a record."""
if not self.env.context.get("auditlog_use_stdout"):
return super().create(vals_list)

self.log_to_stdout(vals_list)
return super().create([])

def log_to_stdout(self, vals_list):
"""Output the values to a logger,
as a JSON value containing all the fields in vals_list.

Optionally, this JSON value can be defined using a system parameter
'auditlog.stdout_log_format_json', to contain a comma-separated
list of keys to use and the format specifiers to fill them from vals,
f.e.:
'{{"user": "{user_id}", "model": "{model_model}", "id": "{res_id}"}}'
"""
log_format = (
self.env["ir.config_parameter"]
.sudo()
.get_param(
"auditlog.stdout_log_format_json",
)
)
for vals in vals_list:
if vals.get("model_id"):
model = self.env["ir.model"].sudo().browse(vals["model_id"])
vals.update({"model_name": model.name, "model_model": model.model})
log_output = json.dumps(vals)
try:
if log_format:
vals_to_use = defaultdict(lambda: "null", vals)
log_output = log_format.format_map(vals_to_use)
json.loads(log_output)
_logger.info(log_output)
except Exception as e:
_logger.info(json.dumps(vals))
_logger.error("auditlogging to standard output failed: %s", str(e))
41 changes: 41 additions & 0 deletions auditlog_stdout/models/auditlog_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class AuditlogRule(models.Model):
_inherit = "auditlog.rule"

stdout = fields.Boolean(
string="Output to STDOUT",
help="If set, the log entries will be only logged to STDOUT "
"(rather than creating an auditlog log and line entries).",
)

def create_logs(
self,
uid,
res_model,
res_ids,
method,
old_values=None,
new_values=None,
additional_log_values=None,
):
"""Pass the auditlog_use_stdout in the context,
later caught in the create of the log entries,
to output the values to STDOUT instead of creating a log entry.
"""
model_id = self.pool._auditlog_model_cache[res_model]
auditlog_rule = self.env["auditlog.rule"].search([("model_id", "=", model_id)])
if auditlog_rule.stdout:
self = self.with_context(auditlog_use_stdout=True)
return super().create_logs(
uid,
res_model,
res_ids,
method,
old_values=old_values,
new_values=new_values,
additional_log_values=additional_log_values,
)
3 changes: 3 additions & 0 deletions auditlog_stdout/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions auditlog_stdout/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Antonio Buric \<<[email protected]>\>
2 changes: 2 additions & 0 deletions auditlog_stdout/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add an option to an auditlog rule to output a log to Odoo's logger
instead of creating auditlog.log and auditlog.log.line records.
Binary file added auditlog_stdout/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading