(38) Log Application

Source: Internet
Author: User

When the application is in production, the logs provide valuable runtime debugging and monitoring information, and
is also a useful debugging tool for applications in the development phase. This article describes the configuration, use, and implementation of log configuration in Odoo8.0
Odoo uses the Python standard log library logging. However, it uses a special configuration syntax to configure the logging level for its modules.
The complete options for the Odoo log configuration are as follows:
LogFile: Log file name, such as Opt/odoo.log. If not set, the default is stdout, which is output to the console
Logrotate:true/false. If set to True, create a file every day and save the log file for 30 days
Log_db:ture/false. If set to True, the log is written to the "ir_logging" table in the database
Log_level: Log level, which can be any item in the list
[' Debug_rpc_answer ', ' Debug_rpc ',
' Debug ', ' Debug_sql ', ' info ',
' Warn ', ' error ', ' critical '.
Odoo Setting this log level option is because these level values are mapped to a pre-defined set of "Module:log_level" key-value pairs.
Even if this option is not set, Odoo uses a predefined setting as the default. See the Log Implementation section below for details.
Log_handler: The value can be a "module:log_level" key-value pair. "Module" means the name of the block, for example: "Openerp.addons.account" or
"Openerp.addons.*". The default value for "Log_level" is "info"-that is, for all modules, the default log level is ' info '

Here is an example log configuration (translator Note: Configuration is generally placed in the openerp-server.conf file), please note that the Log_handler
Configuration syntax--no quotation marks or square brackets on either side of a key-value pair

[Plain]
Log_level = Debug_sql
Log_handler = Openerp.addons.my_addon1:debug,openerp.addons.my_addon2:debug
Using logs in your code
Using the log in the Odoo addon module *.py file is relatively straightforward. For different log levels, the following example code is recommended

[Python]
Import logging

_logger = Logging.getlogger (__name__)

_logger.debug ("Debug Message for Debugging only")
_logger.info ("Information message to report important modular event")
_logger.warning ("warning message to report minor issues")
_logger.error ("error message to report failed operations")
_logger.critical ("Critical message--so bad, the module cannot work")

Implementation of the log
The Odoo log function is defined in "openerp/netsvc.py" and the initialization of the log is defined in the method "Init_logger ()",
After "tools.translated.resetlocal ()" is called, the log is set to the format that contains the following fields:
Time,process id,logging level,database name,module name,logging Message
Example: 2014-09-23 01:32:34,915 42328 INFO odoo openerp.addons.test: Log test (translator added)
If a log file option "LogFile" is configured, the Odoo log uses a file processor
(One of Timedrotatingfilehandler,watchedfilehandler and Filehandler) writes log information to a file.
Processor does not need display settings, if Logrotate is set to True, the processor is timedrotatingfilehandler;
If set to False, the processor is Filehandler or Watchedfilehandler
If the log file option "LogFile" is not configured, the log information is output to the console
If the log database option "log_db" is configured, log information is written to the "ir.logging" table in the database
Odoo reads the log level for different modules from the pre-configured Map key value Object Pseudoconfig_mapper in Odoo
[Python]
Pseudoconfig_mapper = {
' Debug_rpc_answer ': [' openerp:debug ', ' Openerp.http.rpc.request:DEBUG ', ' Openerp.http.rpc.response:DEBUG '],
' Debug_rpc ': [' openerp:debug ', ' Openerp.http.rpc.request:DEBUG '],
' Debug ': [' openerp:debug '],
' Debug_sql ': [' Openerp.sql_db:DEBUG '],
' Info ': [],
' Warn ': [' openerp:warning ', ' werkzeug:warning '],
' ERROR ': [' openerp:error ', ' werkzeug:error '],
' Critical ': [' openerp:critical ', ' werkzeug:critical '],
}
Translator Note: This object is configured in the openerp/netsvc.py file

Odoo reads the log_handler that are configured with the module and log level mappings and is applied in all modules. Default log level: INFO. The following are the default configurations:

[Python]
Default_log_configuration = [
' Openerp.workflow.workitem:WARNING ',
' Openerp.http.rpc.request:INFO ',
' Openerp.http.rpc.response:INFO ',
' Openerp.addons.web.http:INFO ',
' Openerp.sql_db:INFO ',
': INFO ',//set log level for all other modules
]

Translator Note: This object is configured in the openerp/netsvc.py file
Log initialization Call: Method Init_logger () is called by the Parse_config () method in the openerp/tools/config.py file.
The Parse_config () method is also called by the Main method in the openerp/cli/server.py

Original: http://blog.sina.com.cn/s/blog_729a47890102vcoo.html

(38) Log Application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.