odoo日志配置

admin 2022-2-8 82060

Overview

       When the application is in a production environment, the log provides 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 logs in Odoo 8.0

Log configuration

       Odoo uses Python's standard logging library for logging. However, it uses a special configuration syntax to configure log levels for its modules. The following are the complete options for Odoo log configuration:

  1. logfile : log file name, such as opt/odoo.log. If not set, the default is stdout, which is output to the console
  2. logrotate : True/False. If True is set, a file is created every day and the log file is saved for 30 days
  3. log_db : Ture/False. If set to True, the log will be written to the "ir_logging" table in the database
  4. log_level : log level,可以为列表中的任意一项 ['debug_rpc_answer', 'debug_rpc', 'debug', 'debug_sql', 'info', 'warn', 'error', 'critical']. The significance of setting this log level option is that these level values are mapped to a set of pre-defined "module: log_level" key-value pairs. Even if this option is not set, Odoo will use the pre-defined Set as the default. For details, see the log implementation section below.
  5. log_handler : The value can be a "module: log_level" key-value pair. "Module" means the module name, for example: "openerp.addons.account" or "openerp.addons. *". The default value of "log_level" is "INFO"-that is, for all modules, the default log level is 'INFO'

       The following is an example log configuration (just in the 译者注:配置一般放在openerp-server.conffile ), please note the log_handler configuration syntax-there are no quotes or square brackets around the key-value pair

log_level = debug_sql
log_handler = openerp.addons.my_addon1:DEBUG,openerp.addons.my_addon2:DEBUG

Use logs in code

        Using logs in the * .py file of the Odoo addon module is relatively simple. For different log levels, the following example code is recommended

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 that the module cannot work")

Implementation of the log

     The Odoo logging function is defined in "openerp/netsvc.py". The initialization of the log is defined in the method "init_logger ()". After "tools.translated.resetlocal ()" is called, the log is set to contain the following fields format:

                              time, process id, logging level, database name, module name, logging message

       For example: 2014-09-23 01: 32: 34,915 42328 INFO odoo openerp.addons.test: log test (translator added)

  1. If a log file option " logfile " is configured, Odoo log will use a file handler (TimedRotatingFileHandler, WatchedFileHandler and FileHandler) to write log information to a file. (Translator added) The processor does not require display settings, if logrotate is set to True, the processor is TimedRotatingFileHandler; if set to False, the processor is FileHandler or WatchedFileHandler
  2.  If the log file option " logfile " is not configured , the log information will be output to the console
  3. If the log database option " log_db " is configured , the log information will be written to the "ir.logging" table in the database

     Odoo reads the log level for different modules from the pre-configured mapping key value object PSEUDOCONFIG_MAPPER in Odoo

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's Note: This object is configured in the openerp/netsvc.py file.
   
    Odoo reads the log_handler configured with the module and log level mapping and applies it to all modules. Default log level: INFO. The following is the default configuration:
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 the log level for all other modules
]
    Translator's Note: This object is configured in the openerp/netsvc.py file

    Log Initialization call: method init_logger()is openerp/tools/config.pythe file parse_config()方法调用,而 parse_config()method has been openerp/cli/server.pyinvoked in the main method

   Note: The file openerp/loglevels.pydoes not look to be used by any module

-------------------------------

来自于:https://titanwolf.org/Network/Articles/Article?AID=16e9f3b5-67b6-4844-848d-c182b9204e5a

最新回复 (0)
返回