Logger:WARNING just a constant. The constant can be saved to a variable and used later.
$log_level = Logger::WARNING // create a log channel $log = new Logger('name'); $log->pushHandler(new StreamHandler('path/to/your.log', $log_level));
If you need it from the string, then the easiest way to use the dictionary.
$log_level = 'warning'; $possible_levels = ['debug' => Logger::DEBUG, 'info' => Logger::INFO, 'warning' => Logger::WARNING, /*other levels */]; $level = $possible_levels[ $log_level ]; $log = new Logger( 'name' ); $log->pushHandler( new StreamHandler( 'path/to/your.log', $level ) );
If you don’t want to start a dictionary or want to avoid duplication of levels, you can use reflection.
$log_level = 'WARNING'; $LoggerRef = new \ReflectionClass( 'Monolog\Logger' ); $level = $LoggerRef->getConstant( $log_level ); $log = new Logger( 'name' ); $log->pushHandler( new StreamHandler( 'path/to/your.log', $level )