scoutapp / scout-apm-laravel

ScoutAPM PHP Agent for the Laravel Framework
MIT License
22 stars 12 forks source link

Disable or use separate file as logs #60

Closed mfashraf closed 4 years ago

mfashraf commented 4 years ago

Would like to request that logs for scout kept on a separate file because it clogs up the main laravel logs pretty quickly. It also makes it hard for me to work on troubleshooting as I need to sift through a lot of debug logs.

asgrim commented 4 years ago

@mfashraf Hey there, there are two options to achieve what you're trying to do:

1) Easiest option: You can change/add the SCOUT_LOG_LEVEL environment variable in .env (or if you are configuring in config/scout_apm.php, you can add/modify $config[\Scoutapm\Config\ConfigKey::LOG_LEVEL] = \Psr\Log\LogLevel::INFO; for example), or to a higher minimum level (the default is "debug", you could change it to any value listed in \Psr\Log\LogLevel, for example "info", "notice", "warning", etc.)

2) Most control option: You can replace the log used by Scout entirely with a separate \Psr\Log\LoggerInterface. To do this, in a service provider that runs after \Scoutapm\Laravel\Providers\ScoutApmServiceProvider (but before the service is instantiated) you can rewrite the \Scoutapm\Logger\FilteredLogLevelDecorator service, for example:


$this->app->singleton(\Scoutapm\Logger\FilteredLogLevelDecorator::class, static function (Application $app): void {
  $logger = new \Monolog\Logger('scout-only-logs');
  $logger->pushHandler(new \Monolog\Handler\ErrorLogHandler());
  return $logger;
});
kimchirichie commented 4 years ago

also would like to request something like SCOUT_LOG_DISABLE=true

asgrim commented 4 years ago

@kimchirichie as described above, you can either change the SCOUT_LOG_LEVEL to the highest setting (emergency), or inject a NullLogger implementation instead.