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
92 changes: 92 additions & 0 deletions server_action_logging/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
=====================
Server Action Logging
=====================

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

.. |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/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/17.0/server_action_logging
: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-17-0/server-tools-17-0-server_action_logging
: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=17.0
:alt: Try me on Runboat

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

This module allows displaying logs when server actions are executed:

1. a log is generated as soon as an action starts
2. a log is generated if the action is completed without any exception
being raised, and the log displays the duration (in seconds) of the
action itself
3. if action's field ``Enable SQL Debug`` is set, queries are logged too
during the action's execution

**Table of contents**

.. contents::
:local:

Usage
=====

To enable Odoo logs tracking the actions start and duration, you just
need to install this module. To track SQL queries during an action's
execution, open the action form view and check field
``Enable SQL Debug``.

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:%20server_action_logging%0Aversion:%2017.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
=======

Authors
-------

* Camptocamp

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

- Italo LOPES <italo.lopes@camptocamp.com>
- Silvio Gregorini <silvio.gregorini@camptocamp.com>

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/17.0/server_action_logging>`_ 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 server_action_logging/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions server_action_logging/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 Camptocamp (https://www.camptocamp.com).
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

{
"name": "Server Action Logging",
"summary": "Module that provides a logging mechanism for server actions",
"version": "18.0.1.0.0",
"category": "Hidden",
"website": "https://github.com/OCA/server-tools",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "LGPL-3",
"data": ["views/ir_actions_server.xml"],
"installable": True,
"depends": ["base"],
}
34 changes: 34 additions & 0 deletions server_action_logging/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * server_action_logging
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-30 18:33+0000\n"
"PO-Revision-Date: 2024-04-30 18:33+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: server_action_logging
#: model:ir.model.fields,field_description:server_action_logging.field_ir_actions_server__enable_sql_debug
#: model:ir.model.fields,field_description:server_action_logging.field_ir_cron__enable_sql_debug
msgid "Enable SQL Debug"
msgstr "Activer le débogage SQL"

#. module: server_action_logging
#: model:ir.model.fields,help:server_action_logging.field_ir_actions_server__enable_sql_debug
#: model:ir.model.fields,help:server_action_logging.field_ir_cron__enable_sql_debug
msgid "Enable SQL Debug for this action"
msgstr "Activer le débogage SQL pour cette action"

#. module: server_action_logging
#: model:ir.model,name:server_action_logging.model_ir_actions_server
msgid "Server Action"
msgstr ""
34 changes: 34 additions & 0 deletions server_action_logging/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * server_action_logging
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-07-08 10:58+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.6.2\n"

#. module: server_action_logging
#: model:ir.model.fields,field_description:server_action_logging.field_ir_actions_server__enable_sql_debug
#: model:ir.model.fields,field_description:server_action_logging.field_ir_cron__enable_sql_debug
msgid "Enable SQL Debug"
msgstr "Abilita debug SQL"

#. module: server_action_logging
#: model:ir.model.fields,help:server_action_logging.field_ir_actions_server__enable_sql_debug
#: model:ir.model.fields,help:server_action_logging.field_ir_cron__enable_sql_debug
msgid "Enable SQL Debug for this action"
msgstr "Abilita debug SQL per questa azione"

#. module: server_action_logging
#: model:ir.model,name:server_action_logging.model_ir_actions_server
msgid "Server Action"
msgstr "Azione server"
34 changes: 34 additions & 0 deletions server_action_logging/i18n/pt_BR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * server_action_logging
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-30 18:33+0000\n"
"PO-Revision-Date: 2024-04-30 18:33+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: server_action_logging
#: model:ir.model.fields,field_description:server_action_logging.field_ir_actions_server__enable_sql_debug
#: model:ir.model.fields,field_description:server_action_logging.field_ir_cron__enable_sql_debug
msgid "Enable SQL Debug"
msgstr "Ativar depuração SQL"

#. module: server_action_logging
#: model:ir.model.fields,help:server_action_logging.field_ir_actions_server__enable_sql_debug
#: model:ir.model.fields,help:server_action_logging.field_ir_cron__enable_sql_debug
msgid "Enable SQL Debug for this action"
msgstr "Ativar depuração SQL para esta ação"

#. module: server_action_logging
#: model:ir.model,name:server_action_logging.model_ir_actions_server
msgid "Server Action"
msgstr ""
31 changes: 31 additions & 0 deletions server_action_logging/i18n/server_action_logging.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * server_action_logging
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.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: server_action_logging
#: model:ir.model.fields,field_description:server_action_logging.field_ir_actions_server__enable_sql_debug
#: model:ir.model.fields,field_description:server_action_logging.field_ir_cron__enable_sql_debug
msgid "Enable SQL Debug"
msgstr ""

#. module: server_action_logging
#: model:ir.model.fields,help:server_action_logging.field_ir_actions_server__enable_sql_debug
#: model:ir.model.fields,help:server_action_logging.field_ir_cron__enable_sql_debug
msgid "Enable SQL Debug for this action"
msgstr ""

#. module: server_action_logging
#: model:ir.model,name:server_action_logging.model_ir_actions_server
msgid "Server Action"
msgstr ""
1 change: 1 addition & 0 deletions server_action_logging/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ir_actions_server
41 changes: 41 additions & 0 deletions server_action_logging/models/ir_actions_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 Camptocamp (https://www.camptocamp.com).
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

import logging

from odoo import fields, models

_logger = logging.getLogger(__name__)


class IrActionsServer(models.Model):
_inherit = "ir.actions.server"

enable_sql_debug = fields.Boolean(
string="Enable SQL Debug",
help="Enable SQL Debug for this action",
default=False, # Avoid too much log pollution
)

def run(self):
if self.env.context.get("server_action_run_with_logs"): # Avoid recursion
return super().run()

actions = self.with_context(server_action_run_with_logs=True)
odoo_sql_db_logger = logging.getLogger("odoo.sql_db")
odoo_sql_db_logger_level = odoo_sql_db_logger.level
odoo_sql_db_logger_has_debug = odoo_sql_db_logger.isEnabledFor(logging.DEBUG)
res = False
for act in actions:
force_sql_debug = not odoo_sql_db_logger_has_debug and act.enable_sql_debug
if force_sql_debug:
odoo_sql_db_logger.setLevel(logging.DEBUG)
subject = f"Action {act.display_name} ({act})"
_logger.info(f"{subject} started")
start = fields.Datetime.now()
res = act.run()
delta = (fields.Datetime.now() - start).total_seconds()
_logger.info(f"{subject} completed in {delta:.3f} seconds")
if force_sql_debug:
odoo_sql_db_logger.setLevel(odoo_sql_db_logger_level)
return res or False
3 changes: 3 additions & 0 deletions server_action_logging/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions server_action_logging/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Italo LOPES \<<italo.lopes@camptocamp.com>\>
- Silvio Gregorini \<<silvio.gregorini@camptocamp.com>\>
8 changes: 8 additions & 0 deletions server_action_logging/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This module allows displaying logs when server actions are executed:

1. a log is generated as soon as an action starts
2. a log is generated if the action is completed without any exception
being raised, and the log displays the duration (in seconds) of the
action itself
3. if action's field `Enable SQL Debug` is set, queries are logged too
during the action's execution
3 changes: 3 additions & 0 deletions server_action_logging/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To enable Odoo logs tracking the actions start and duration, you just
need to install this module. To track SQL queries during an action's
execution, open the action form view and check field `Enable SQL Debug`.
Binary file added server_action_logging/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