문제

I'm using Silex 1.1 and Monolog 1.0.0. My code and my problem:

$app->register(new Silex\Provider\MonologServiceProvider(), array(
  'monolog.name' => 'myname',
  'monolog.logfile' => ROOT . '/logs/log.txt',
  'monolog.level'   => Monolog\Logger::INFO
));

. . .
$app['monolog']->addInfo('xxx');

Everything works fine, but I get default messages like these:

[2013-12-13 00:20:56] myname.INFO: Matched route "GET_api_v1_predictions" (parameters: "_controller": "predictions.controller:index", "_route": "GET_api_v1_predictions") [] []
[2013-12-13 00:20:56] myname.INFO: > GET /api/v1/predictions [] []

How I can disable them? (If I change the logging level to WARNING and use addWarning then just my messages are displayed, but I want to use the INFO level).

도움이 되었습니까?

해결책

You can still create a logger for your application which is not used by other processes:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// initialize the logger
$app['mylog'] = $app->share(function($app) {
   return new Logger('mylog');
});
$app['mylog']->pushHandler(new StreamHandler('/logfile/mylog.log', Logger::INFO));
$app['mylog']->addInfo('Private Log initialized');

다른 팁

Currently there's no way to disable them, the log commands are registered unconditionally.

The short-term solution is to copy MonologServiceProvider into your own app, change the log commands as you need.

The long-term solution is to fork the silex repository, change the MonologServiceProvider to provide a way to disable those commands, then create a pull request so everyone can enjoy your work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top