Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration of log handlers #16

Open
guewen opened this issue Mar 7, 2018 · 1 comment
Open

Configuration of log handlers #16

guewen opened this issue Mar 7, 2018 · 1 comment

Comments

@guewen
Copy link
Contributor

guewen commented Mar 7, 2018

Pytest adds a new --odoo-log-level option which is forwarded as odoo's log level.
By default it uses the critical log level to display the less logs possible. But you can change it when you need more details for debugging a test.

Odoo has 2 options for configuring log levels:

  • --log-level: a global single level (critical, error, info, debug, ...)
  • --log-handler: a refined log level per logger name (':INFO,odoo.http.rpc.request:INFO')

The first one is based on this config:

{'critical': ['odoo:CRITICAL', 'werkzeug:CRITICAL'],
 'debug': ['odoo:DEBUG', 'odoo.sql_db:INFO'],
 'debug_rpc': ['odoo:DEBUG', 'odoo.sql_db:INFO', 'odoo.http.rpc.request:DEBUG'],
 'debug_rpc_answer': ['odoo:DEBUG', 'odoo.sql_db:INFO', 'odoo.http.rpc:DEBUG'],
 'debug_sql': ['odoo.sql_db:DEBUG'],
 'error': ['odoo:ERROR', 'werkzeug:ERROR'],
 'info': [],
 'warn': ['odoo:WARNING', 'werkzeug:WARNING']}

And the second one will be applied after the --log-level, so it overrides it.
The default log handler is :INFO.

The result is that when you use a command such as (both are the same):

pytest -s my_addon/tests --odoo-log-level=critical
# means critical log-level
pytest -s my_addon/tests

The log levels will be:

:INFO
odoo:CRITICAL
werkzeug:CRITICAL

As the log levels are recursive, all the loggers below odoo (odoo.addons.sale, ...) and werkzeug will be on the critical log-level. But all other loggers, such as those used by libs (Pillow, ...) will have an INFO logger by default.

What we should probably do is set a default --log-handler to :CRITICAL and add an option to modify it the same way it's done for the log level.

As a workaround, you can use a configuration file (

or os.environ.get('OPENERP_SERVER')):
) and set the log handler configuration into it.

Now, we observed in #15 that even logs in DEBUG of Pillow (and passlib) were shown, and they should have been hidden as the default is INFO.

The reason is that each test is in a context manager (pytest.logging.catching_logs) which, during the duration of the test, sets the root loglevel to zero (0 is below DEBUG, display everything). Predefined children log levels will not be changed, but others will all show debug logs. (introduced at pytest-dev/pytest#3013)

The context manager: https://github.com/pytest-dev/pytest/blob/5ad1313b8a18fa3862623d2360cbeb39c202b838/_pytest/logging.py#L84-L106

Hopefully, it has been fixed in pytest 3.4.2 (pytest-dev/pytest@8dcd271)

@simahawk
Copy link
Member

@guewen I upgraded to pytest 3.5.0 right now and it really fixes this ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants