1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 17:16:18 +02:00
This commit is contained in:
Jordi Boggiano
2016-05-26 20:54:06 +01:00
parent 85e43a5e7b
commit f200e79879
115 changed files with 1138 additions and 1123 deletions

View File

@@ -23,7 +23,7 @@ class ChromePHPFormatter implements FormatterInterface
/**
* Translates Monolog log levels to Wildfire levels.
*/
private $logLevels = array(
private $logLevels = [
Logger::DEBUG => 'log',
Logger::INFO => 'info',
Logger::NOTICE => 'info',
@@ -32,7 +32,7 @@ class ChromePHPFormatter implements FormatterInterface
Logger::CRITICAL => 'error',
Logger::ALERT => 'error',
Logger::EMERGENCY => 'error',
);
];
/**
* {@inheritdoc}
@@ -46,7 +46,7 @@ class ChromePHPFormatter implements FormatterInterface
unset($record['extra']['file'], $record['extra']['line']);
}
$message = array('message' => $record['message']);
$message = ['message' => $record['message']];
if ($record['context']) {
$message['context'] = $record['context'];
}
@@ -57,17 +57,17 @@ class ChromePHPFormatter implements FormatterInterface
$message = reset($message);
}
return array(
return [
$record['channel'],
$message,
$backtrace,
$this->logLevels[$record['level']],
);
];
}
public function formatBatch(array $records)
{
$formatted = array();
$formatted = [];
foreach ($records as $record) {
$formatted[] = $this->format($record);

View File

@@ -43,11 +43,11 @@ class FlowdockFormatter implements FormatterInterface
*/
public function format(array $record)
{
$tags = array(
$tags = [
'#logs',
'#' . strtolower($record['level_name']),
'#' . $record['channel'],
);
];
foreach ($record['extra'] as $value) {
$tags[] = '#' . $value;
@@ -60,14 +60,14 @@ class FlowdockFormatter implements FormatterInterface
$this->getShortMessage($record['message'])
);
$record['flowdock'] = array(
$record['flowdock'] = [
'source' => $this->source,
'from_address' => $this->sourceEmail,
'subject' => $subject,
'content' => $record['message'],
'tags' => $tags,
'project' => $this->source,
);
];
return $record;
}
@@ -77,7 +77,7 @@ class FlowdockFormatter implements FormatterInterface
*/
public function formatBatch(array $records)
{
$formatted = array();
$formatted = [];
foreach ($records as $record) {
$formatted[] = $this->format($record);

View File

@@ -60,17 +60,17 @@ class FluentdFormatter implements FormatterInterface
$tag .= '.' . strtolower($record['level_name']);
}
$message = array(
$message = [
'message' => $record['message'],
'extra' => $record['extra'],
);
];
if (!$this->levelTag) {
$message['level'] = $record['level'];
$message['level_name'] = $record['level_name'];
}
return json_encode(array($tag, $record['datetime']->getTimestamp(), $message));
return json_encode([$tag, $record['datetime']->getTimestamp(), $message]);
}
public function formatBatch(array $records)

View File

@@ -42,7 +42,7 @@ class GelfMessageFormatter extends NormalizerFormatter
/**
* Translates Monolog log levels to Graylog2 log priorities.
*/
private $logLevels = array(
private $logLevels = [
Logger::DEBUG => 7,
Logger::INFO => 6,
Logger::NOTICE => 5,
@@ -51,7 +51,7 @@ class GelfMessageFormatter extends NormalizerFormatter
Logger::CRITICAL => 2,
Logger::ALERT => 1,
Logger::EMERGENCY => 0,
);
];
public function __construct($systemName = null, $extraPrefix = null, $contextPrefix = 'ctxt_')
{

View File

@@ -24,7 +24,7 @@ class HtmlFormatter extends NormalizerFormatter
/**
* Translates Monolog log levels to html color priorities.
*/
protected $logLevels = array(
protected $logLevels = [
Logger::DEBUG => '#cccccc',
Logger::INFO => '#468847',
Logger::NOTICE => '#3a87ad',
@@ -33,7 +33,7 @@ class HtmlFormatter extends NormalizerFormatter
Logger::CRITICAL => '#FF7708',
Logger::ALERT => '#C12A19',
Logger::EMERGENCY => '#000000',
);
];
/**
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format

View File

@@ -138,7 +138,7 @@ class JsonFormatter extends NormalizerFormatter
protected function normalize($data)
{
if (is_array($data) || $data instanceof \Traversable) {
$normalized = array();
$normalized = [];
$count = 1;
foreach ($data as $key => $value) {
@@ -169,12 +169,12 @@ class JsonFormatter extends NormalizerFormatter
*/
protected function normalizeException(\Throwable $e)
{
$data = array(
$data = [
'class' => get_class($e),
'message' => $e->getMessage(),
'code' => $e->getCode(),
'file' => $e->getFile().':'.$e->getLine(),
);
];
if ($this->includeStacktraces) {
$trace = $e->getTrace();

View File

@@ -155,6 +155,6 @@ class LineFormatter extends NormalizerFormatter
return $str;
}
return str_replace(array("\r\n", "\r", "\n"), ' ', $str);
return str_replace(["\r\n", "\r", "\n"], ' ', $str);
}
}

View File

@@ -69,11 +69,11 @@ class LogstashFormatter extends NormalizerFormatter
if (empty($record['datetime'])) {
$record['datetime'] = gmdate('c');
}
$message = array(
$message = [
'@timestamp' => $record['datetime'],
'@version' => 1,
'host' => $this->systemName,
);
];
if (isset($record['message'])) {
$message['message'] = $record['message'];
}

View File

@@ -84,12 +84,12 @@ class MongoDBFormatter implements FormatterInterface
protected function formatException(\Throwable $exception, $nestingLevel)
{
$formattedException = array(
$formattedException = [
'class' => get_class($exception),
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
'file' => $exception->getFile() . ':' . $exception->getLine(),
);
];
if ($this->exceptionTraceAsString === true) {
$formattedException['trace'] = $exception->getTraceAsString();

View File

@@ -72,7 +72,7 @@ class NormalizerFormatter implements FormatterInterface
}
if (is_array($data) || $data instanceof \Traversable) {
$normalized = array();
$normalized = [];
$count = 1;
foreach ($data as $key => $value) {
@@ -90,6 +90,7 @@ class NormalizerFormatter implements FormatterInterface
if ($data instanceof DateTimeImmutable) {
return (string) $data;
}
return $data->format($this->dateFormat ?: static::SIMPLE_DATE);
}
@@ -124,12 +125,12 @@ class NormalizerFormatter implements FormatterInterface
protected function normalizeException(Throwable $e)
{
$data = array(
$data = [
'class' => get_class($e),
'message' => $e->getMessage(),
'code' => $e->getCode(),
'file' => $e->getFile().':'.$e->getLine(),
);
];
$trace = $e->getTrace();
foreach ($trace as $frame) {
@@ -176,7 +177,7 @@ class NormalizerFormatter implements FormatterInterface
}
/**
* @param mixed $data
* @param mixed $data
* @return string|bool JSON encoded data or false on failure
*/
private function jsonEncode($data)
@@ -206,7 +207,7 @@ class NormalizerFormatter implements FormatterInterface
if (is_string($data)) {
$this->detectAndCleanUtf8($data);
} elseif (is_array($data)) {
array_walk_recursive($data, array($this, 'detectAndCleanUtf8'));
array_walk_recursive($data, [$this, 'detectAndCleanUtf8']);
} else {
$this->throwEncodeError($code, $data);
}
@@ -274,8 +275,8 @@ class NormalizerFormatter implements FormatterInterface
$data
);
$data = str_replace(
array('¤', '¦', '¨', '´', '¸', '¼', '½', '¾'),
array('€', 'Š', 'š', 'Ž', 'ž', 'Œ', 'œ', 'Ÿ'),
['¤', '¦', '¨', '´', '¸', '¼', '½', '¾'],
['€', 'Š', 'š', 'Ž', 'ž', 'Œ', 'œ', 'Ÿ'],
$data
);
}

View File

@@ -27,7 +27,7 @@ class WildfireFormatter extends NormalizerFormatter
/**
* Translates Monolog log levels to Wildfire levels.
*/
private $logLevels = array(
private $logLevels = [
Logger::DEBUG => 'LOG',
Logger::INFO => 'INFO',
Logger::NOTICE => 'INFO',
@@ -36,7 +36,7 @@ class WildfireFormatter extends NormalizerFormatter
Logger::CRITICAL => 'ERROR',
Logger::ALERT => 'ERROR',
Logger::EMERGENCY => 'ERROR',
);
];
/**
* {@inheritdoc}
@@ -55,7 +55,7 @@ class WildfireFormatter extends NormalizerFormatter
}
$record = $this->normalize($record);
$message = array('message' => $record['message']);
$message = ['message' => $record['message']];
$handleError = false;
if ($record['context']) {
$message['context'] = $record['context'];
@@ -79,15 +79,15 @@ class WildfireFormatter extends NormalizerFormatter
}
// Create JSON object describing the appearance of the message in the console
$json = $this->toJson(array(
array(
$json = $this->toJson([
[
'Type' => $type,
'File' => $file,
'Line' => $line,
'Label' => $label,
),
],
$message,
), $handleError);
], $handleError);
// The message itself is a serialization of the above JSON object + it's length
return sprintf(