Setting a Minimum Log Level

It may be useful to not log events when the log level is below a certain threshold. For example, on a dev site, you might want to log everything. On a production site, you may only want to log events that are more serious. You can set a minimum log level on each adapter to indicate the level an event must be at (or higher) before it is logged.

The log level precedence is as follows (from least concern to highest concern):

  • LogLevel::DEBUG
  • LogLevel::INFO,
  • LogLevel::NOTICE,
  • LogLevel::WARNING,
  • LogLevel::ERROR,
  • LogLevel::CRITICAL,
  • LogLevel::ALERT,
  • LogLevel::EMERGENCY,
1
2
3
4
5
6
7
8
<?php
use Vespula\Log\Adapter\ErrorLog;
use Psr\Log\LogLevel;

$adapter = ErrorLog(ErrorLog::TYPE_FILE, '/myapp/logs/mylog.txt');

// only WARNING and higher will be logged by this adapter.
$adapter->setMinLevel(LogLevel::WARNING);