跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. Odoo Logging 的配置,使用和实现

Odoo Logging 的配置,使用和实现

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
4 帖子 2 发布者 4.4k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • Y 离线
    Y 离线
    Ying Liu
    写于 最后由 编辑
    #1

    Odoo Logging Configuration, Usage and Implementation
    转自本人博客( [检测到链接无效,已移除]

    Overview
    Logging provides valuable runtime debugging/monitoring information when an application is on production. It is also a helpful tool in debugging application in development phase. This blog describes the logging configuration, usage and implementation in Odoo 8.0.

    logging configuration
    Odoo uses the Python standard logging library. However, it uses a special configuration syntax to configure logging levels for its modules. Following are a complete list of Odoo logging configuration options:

    logfile: the log filename. If not set, use stdout.
    logrotate: True/False. If True, create a daily log file and keep 30 files.
    log_db: Ture/False. If Ture, also write log to 'ir_logging' table in database.
    log_level: any value in the list of ['debug_rpc_answer', 'debug_rpc', 'debug', 'debug_sql', 'info', 'warn', 'error', 'critical']. Odoo changed the log_level meaning here because this level values are mapped to a set of predefined 'module:log_level' pairs. Even this option is not set, there is a set of predefined settings. See the following implementation section for details.
    log_handler: can be a list of 'module:log_level' pairs. The default value is ':INFO' -- it means the default logging level is 'INFO' for all modules.
    logging in your code
    Using logging in an Odoo addon is simple. The following is an example with the recommended use of different logging levels:

    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")

    Examples of logging configuration are listed below. Please pay attention to the syntax of log_handler -- not quotation or square bracket around the value.

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

    ## Odoo logging implementation

    Odoo logging functions are defined in openerpr/netsvc.py.
    Logging initialization is defined in the init_logger() function.
    After calling tools.translated.resetlocal(), it sets a
    logging format that consists of the following fields:

    > time, process id, logging level, database name, module name,
    > and logging message.

    If a logfile configuration option is provided, it uses a file
    handler (one of TimedRotatingFileHandler, WatchedFileHandler,
    and FileHandler) to log messages to a file.
    If no logfile is configured, it logs messages to stdout.
    If log_db is configured with a database name, it logs message
    to the ir.logging table in the specified database.

    It reads log_level configuration option that is pre-mapped as one of the
    following:

    ```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'],
    }
    It reads log_handler configuration option that defines mappings of a module and its logging level. The default is :INFO. Then it combines the mapped value of log_level option, log_handler and the following default logging 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',
    ]
    Finally, it set logging level for every module in the combined list of 'module:log_level' pairs.

    The init_logger() is called by parse_config() method in openerp/tools/config.py that is called by the main() method in openerp/cli/server.py.

    Note: it seems that the openerp/loglevels.py is not used by any module.

    1 条回复 最后回复
    0
    • C 离线
      C 离线
      claro
      写于 最后由 编辑
      #2

      odoo8.0在IDE中调试时,debug哪个文件呢?
      因为没有7.0的openerp-server,是要复制过去吗?

      1 条回复 最后回复
      0
      • Y 离线
        Y 离线
        Ying Liu
        写于 最后由 编辑
        #3

        odoo 8.0 还是从 openerp-server 开始启动运行的。 这里有个以前发的不错的帖子 [检测到链接无效,已移除]

        1 条回复 最后回复
        0

        • 登录

        • 没有帐号? 注册

        • 登录或注册以进行搜索。
        • 第一个帖子
          最后一个帖子
        0
        • 版块
        • 标签
        • 热门
        • 用户
        • 群组