代码之家  ›  专栏  ›  技术社区  ›  Matt Sidesinger

Symfony日志记录

  •  3
  • Matt Sidesinger  · 技术社区  · 16 年前

    这是一个日志框架。在Log4j中,你可以这样做:

    if (log.isDebug()) {
      // do some expensive operation that should only be displayed if DEBUG is turned on
    }
    

    if (--need something here--) {
      $this->logMessage('Expensive operation return value: '.expensiveFunction(), 'debug');
    }
    
    5 回复  |  直到 12 年前
        1
  •  5
  •   ax. Clement Herreman    16 年前

    大约

    $this->getLogger()->getLogLevel() == sfLogger::DEBUG
    

    应该这样做。

        2
  •  3
  •   Geshan    11 年前
        3
  •  0
  •   Fracsi    12 年前

    您也可以尝试: sfConfig::get('sf_logging_enabled').

        4
  •  0
  •   Valentin Hristov    9 年前

    您可以通过以下方式检查是否处于调试模式:

    if ($this->get('kernel')->isDebug()) {
        ...
    }
    

    https://symfony.com/doc/2.8/components/console/logger.html http://symfony.com/doc/current/cookbook/logging/index.html

        5
  •  0
  •   Ricardo    9 年前

    您可以使用symfony记录器服务 如果你在控制器中,你可以使用以下代码调用此服务:

    if ($this->get('kernel')->isDebug()) {
     $this->get('logger')->err('my custom message');
    }
    

    如果你想改进你的系统,你可以查看MonologBundle http://symfony.com/doc/current/logging.html