本文整理汇总了PHP中Monolog\Logger::getLevelName方法的典型用法代码示例。如果您正苦于以下问题:PHP Logger::getLevelName方法的具体用法?PHP Logger::getLevelName怎么用?PHP Logger::getLevelName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Monolog\Logger
的用法示例。
在下文中一共展示了Logger::getLevelName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
* {@inheritDoc}
*/
protected function write(array $record)
{
$data = $record['context'];
$data['level'] = Logger::getLevelName($record['level']);
$data['message'] = $record['message'];
$this->logger->post($record['channel'], $data);
}
示例2: testHandlerUsesLineFormatterWhichIgnoresEmptyArrays
/**
* @covers ::getDefaultFormatter
*/
public function testHandlerUsesLineFormatterWhichIgnoresEmptyArrays()
{
$record = array('message' => 'msg', 'context' => array(), 'level' => Logger::DEBUG, 'level_name' => Logger::getLevelName(Logger::DEBUG), 'channel' => 'channel', 'datetime' => new \DateTime(), 'extra' => array());
$expectedFormatter = new LineFormatter(null, null, true, true);
$expected = $expectedFormatter->format($record);
$handlerFormatter = $this->handler->getFormatter();
$actual = $handlerFormatter->format($record);
$this->assertEquals($expected, $actual, 'Empty context and extra arrays should not be rendered');
}
示例3: testWrite
public function testWrite()
{
$data = $this->record;
$data['level'] = Logger::getLevelName($data['level']);
$tag = $data['channel'] . '.' . $data['message'];
$loggerMock = $this->getMockBuilder('Fluent\\Logger\\FluentLogger')->disableOriginalConstructor()->getMock();
$loggerMock->expects($this->once())->method('post')->with('debug.monolog.fluent', $data);
$handler = new FluentHandler($loggerMock);
$handler->write($this->record);
}
示例4: testWritingAndFormatting
public function testWritingAndFormatting()
{
$output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
$output->expects($this->any())->method('getVerbosity')->will($this->returnValue(OutputInterface::VERBOSITY_DEBUG));
$output->expects($this->once())->method('write')->with('<info>[2013-05-29 16:21:54] app.INFO:</info> My info message ' . "\n");
$handler = new ConsoleHandler(null, false);
$handler->setOutput($output);
$infoRecord = array('message' => 'My info message', 'context' => array(), 'level' => Logger::INFO, 'level_name' => Logger::getLevelName(Logger::INFO), 'channel' => 'app', 'datetime' => new \DateTime('2013-05-29 16:21:54'), 'extra' => array());
$this->assertTrue($handler->handle($infoRecord), 'The handler finished handling the log as bubble is false.');
}
示例5: testWrite
public function testWrite()
{
$fluentLogger = $this->getMock('Fluent\\Logger\\FluentLogger', array(), array(), '', false);
$record = $this->getRecord();
$expectedContext = $record['context'];
$expectedContext['level'] = Logger::getLevelName($record['level']);
$expectedContext['message'] = $record['message'];
$fluentLogger->expects($this->once())->method('post')->with($record['channel'], $expectedContext);
$handler = new FluentdHandler($fluentLogger);
$handler->handle($record);
}
示例6: getRecord
/**
* @return array Record
*/
protected function getRecord($level = Logger::WARNING, $message = 'test')
{
return array(
'message' => $message,
'context' => array(),
'level' => $level,
'level_name' => Logger::getLevelName($level),
'channel' => 'test',
'datetime' => new \DateTime(),
'extra' => array(),
);
}
示例7: write
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
if (isset($record['context']) && isset($record['context']['tag'])) {
$tag = $record['context']['tag'];
} else {
$tag = $this->tag;
}
$tag = $tag . '.' . $this->env;
$data = $record;
$data['level'] = Logger::getLevelName($record['level']);
$this->logger->post($tag, $data);
}
示例8: save
/**
* Save records into database in batch
*
* @param array $records
*
* @throws \Exception
*/
protected function save(array $records)
{
if ($this->hasError === true) {
$this->fallback->handleBatch($records);
return;
}
$data = [];
foreach ($records as $record) {
// ['message', 'context', 'level', 'channel', 'created_at', 'extra'] <= Single row format
$data[] = [Log::FIELD_MESSAGE => $record['message'], Log::FIELD_CONTEXT => serialize((array) $record['context']), Log::FIELD_LEVEL => Logger::getLevelName($record['level']), Log::FIELD_CHANNEL => $record['channel'], Log::FIELD_CREATED_AT => $record['datetime'] instanceof \DateTime ? Carbon::instance($record['datetime']) : Carbon::now(), Log::FIELD_EXTRA => serialize((array) $record['extra'])];
}
try {
$this->container->make('db')->connection()->table((new Log())->getTable())->insert($data);
} catch (\Exception $ex) {
$this->hasError = true;
$this->fallback->handleBatch($records);
throw $ex;
}
}
示例9: testProvidingNullLineFormatToGetMonologDefault
public function testProvidingNullLineFormatToGetMonologDefault()
{
$logfileName = 'nullFormatterTest.log';
$this->cleanUpLogFile($logfileName);
$command = $this->registerCommand(new LoggingCommand());
EncapsulationViolator::invokeMethod($command, 'setLogFilename', array($logfileName));
EncapsulationViolator::invokeMethod($command, 'setConsoleLogLineFormat', array(null));
EncapsulationViolator::invokeMethod($command, 'setFileLogLineFormat', array(null));
$commandTester = $this->executeCommand($command);
// Generate what the default format looks like
$lineFormatter = new \Monolog\Formatter\LineFormatter(null);
$record = array('message' => 'The quick brown fox jumps over the lazy dog', 'context' => array(), 'level' => Logger::EMERGENCY, 'level_name' => Logger::getLevelName(Logger::EMERGENCY), 'channel' => $command->getLogger()->getName(), 'datetime' => new \DateTime('1970-01-01 00:00:00'), 'extra' => array());
$exampleLine = $lineFormatter->format($record);
$exampleLine = trim(str_replace('[1970-01-01 00:00:00]', '', $exampleLine));
// strip out date as this wont match
// Test console format
$this->assertRegExp('/' . $exampleLine . '/', $commandTester->getDisplay(), 'Console log line format does not seem to match the Monolog default');
// Test default logfile format
$this->assertRegExp('/' . $exampleLine . '/', $this->getLogfileContents($logfileName), 'File log line format does not seem to match the Monolog default');
$this->cleanUpLogFile($logfileName);
}
示例10: parseLogLevel
/**
* Converts a given log level string to a log level integer.
*
* @param string $logLevelStr Values could be DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY
* @return int
* @throws \Exception
*/
public static function parseLogLevel($logLevelStr)
{
if (is_numeric($logLevelStr)) {
return (int) $logLevelStr;
} else {
switch (strtoupper($logLevelStr)) {
case Logger::getLevelName(Logger::DEBUG):
$logLevel = Logger::DEBUG;
break;
case Logger::getLevelName(Logger::INFO):
$logLevel = Logger::INFO;
break;
case Logger::getLevelName(Logger::NOTICE):
$logLevel = Logger::NOTICE;
break;
case Logger::getLevelName(Logger::WARNING):
$logLevel = Logger::WARNING;
break;
case Logger::getLevelName(Logger::ERROR):
$logLevel = Logger::ERROR;
break;
case Logger::getLevelName(Logger::CRITICAL):
$logLevel = Logger::CRITICAL;
break;
case Logger::getLevelName(Logger::ALERT):
$logLevel = Logger::ALERT;
break;
case Logger::getLevelName(Logger::EMERGENCY):
$logLevel = Logger::EMERGENCY;
break;
default:
throw new \Exception("Log level '{$logLevelStr}' is not supported!'");
}
return $logLevel;
}
}
示例11: getRecord
/**
* @return array Record
*/
protected function getRecord($level = Logger::WARNING, $message = 'test', $context = array())
{
return array('message' => $message, 'context' => $context, 'level' => $level, 'level_name' => Logger::getLevelName($level), 'channel' => 'test', 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))), 'extra' => array());
}
示例12: logLevel
/**
* Convert a Monolog log level to textual equivalent.
*
* @param integer $level
*
* @return string
*/
public function logLevel($level)
{
if (!is_numeric($level)) {
return $level;
}
try {
return ucfirst(strtolower(\Monolog\Logger::getLevelName($level)));
} catch (\Exception $e) {
return $level;
}
}
示例13: getRecord
protected function getRecord($level = Logger::WARNING)
{
return array('level' => $level, 'level_name' => Logger::getLevelName($level), 'channel' => 'log', 'Record' => 'foo', 'datetime' => new \DateTime(), 'extra' => array());
}
示例14: getLevelName
public static function getLevelName($level)
{
return Logger::getLevelName($level);
}
示例15: getRecord
/**
* @return array Record
*/
protected function getRecord($level = Logger::WARNING, $message = 'test', $context = [])
{
return ['message' => $message, 'context' => $context, 'level' => $level, 'level_name' => Logger::getLevelName($level), 'channel' => 'test', 'datetime' => new DateTimeImmutable(true), 'extra' => []];
}