Skip to content

Commit

Permalink
Logger: renamed $priority -> $level
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 15, 2019
1 parent 29af14d commit 1cd808a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/Bridges/Psr/PsrToTracyLoggerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
class PsrToTracyLoggerAdapter implements Tracy\ILogger
{
/** Tracy logger priority to PSR-3 log level mapping */
private const PRIORITY_MAP = [
/** Tracy logger level to PSR-3 log level mapping */
private const LEVEL_MAP = [
Tracy\ILogger::DEBUG => Psr\Log\LogLevel::DEBUG,
Tracy\ILogger::INFO => Psr\Log\LogLevel::INFO,
Tracy\ILogger::WARNING => Psr\Log\LogLevel::WARNING,
Expand All @@ -38,7 +38,7 @@ public function __construct(Psr\Log\LoggerInterface $psrLogger)
}


public function log($value, $priority = self::INFO)
public function log($value, $level = self::INFO)
{
if ($value instanceof \Throwable) {
$message = Tracy\Helpers::getClass($value) . ': ' . $value->getMessage() . ($value->getCode() ? ' #' . $value->getCode() : '') . ' in ' . $value->getFile() . ':' . $value->getLine();
Expand All @@ -54,7 +54,7 @@ public function log($value, $priority = self::INFO)
}

$this->psrLogger->log(
self::PRIORITY_MAP[$priority] ?? Psr\Log\LogLevel::ERROR,
self::LEVEL_MAP[$level] ?? Psr\Log\LogLevel::ERROR,
$message,
$context
);
Expand Down
10 changes: 5 additions & 5 deletions src/Bridges/Psr/TracyToPsrLoggerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
class TracyToPsrLoggerAdapter extends Psr\Log\AbstractLogger
{
/** PSR-3 log level to Tracy logger priority mapping */
private const PRIORITY_MAP = [
/** PSR-3 log level to Tracy logger level mapping */
private const LEVEL_MAP = [
Psr\Log\LogLevel::EMERGENCY => Tracy\ILogger::CRITICAL,
Psr\Log\LogLevel::ALERT => Tracy\ILogger::CRITICAL,
Psr\Log\LogLevel::CRITICAL => Tracy\ILogger::CRITICAL,
Expand All @@ -42,10 +42,10 @@ public function __construct(Tracy\ILogger $tracyLogger)

public function log($level, $message, array $context = [])
{
$priority = self::PRIORITY_MAP[$level] ?? Tracy\ILogger::ERROR;
$level = self::LEVEL_MAP[$level] ?? Tracy\ILogger::ERROR;

if (isset($context['exception']) && $context['exception'] instanceof \Throwable) {
$this->tracyLogger->log($context['exception'], $priority);
$this->tracyLogger->log($context['exception'], $level);
unset($context['exception']);
}

Expand All @@ -56,6 +56,6 @@ public function log($level, $message, array $context = [])
];
}

$this->tracyLogger->log($message, $priority);
$this->tracyLogger->log($message, $level);
}
}
4 changes: 2 additions & 2 deletions src/Tracy/Debugger/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,9 @@ public static function barDump($var, string $title = null, array $options = [])
* @param mixed $message
* @return mixed
*/
public static function log($message, string $priority = ILogger::INFO)
public static function log($message, string $level = ILogger::INFO)
{
return self::getLogger()->log($message, $priority);
return self::getLogger()->log($message, $level);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Tracy/Logger/FireLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class FireLogger implements ILogger
* Sends message to FireLogger console.
* @param mixed $message
*/
public function log($message, $priority = self::DEBUG): bool
public function log($message, $level = self::DEBUG): bool
{
if (!isset($_SERVER['HTTP_X_FIRELOGGER']) || headers_sent()) {
return false;
}

$item = [
'name' => 'PHP',
'level' => $priority,
'level' => $level,
'order' => count($this->payload['logs']),
'time' => str_pad(number_format((microtime(true) - Debugger::$time) * 1000, 1, '.', ' '), 8, '0', STR_PAD_LEFT) . ' ms',
'template' => '',
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/Logger/ILogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ interface ILogger
EXCEPTION = 'exception',
CRITICAL = 'critical';

function log($value, $priority = self::INFO);
function log($value, $level = self::INFO);
}
8 changes: 4 additions & 4 deletions src/Tracy/Logger/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public function __construct(?string $directory, $email = null, BlueScreen $blueS
/**
* Logs message or exception to file and sends email notification.
* @param mixed $message
* @param string $priority one of constant ILogger::INFO, WARNING, ERROR (sends email), EXCEPTION (sends email), CRITICAL (sends email)
* @param string $level one of constant ILogger::INFO, WARNING, ERROR (sends email), EXCEPTION (sends email), CRITICAL (sends email)
* @return string|null logged error filename
*/
public function log($message, $priority = self::INFO)
public function log($message, $level = self::INFO)
{
if (!$this->directory) {
throw new \LogicException('Logging directory is not specified.');
Expand All @@ -64,7 +64,7 @@ public function log($message, $priority = self::INFO)
? $this->getExceptionFile($message)
: null;
$line = static::formatLogLine($message, $exceptionFile);
$file = $this->directory . '/' . strtolower($priority ?: self::INFO) . '.log';
$file = $this->directory . '/' . strtolower($level ?: self::INFO) . '.log';

if (!@file_put_contents($file, $line . PHP_EOL, FILE_APPEND | LOCK_EX)) { // @ is escalated to exception
throw new \RuntimeException("Unable to write to log file '$file'. Is directory writable?");
Expand All @@ -74,7 +74,7 @@ public function log($message, $priority = self::INFO)
$this->logException($message, $exceptionFile);
}

if (in_array($priority, [self::ERROR, self::EXCEPTION, self::CRITICAL], true)) {
if (in_array($level, [self::ERROR, self::EXCEPTION, self::CRITICAL], true)) {
$this->sendEmail($message);
}

Expand Down

0 comments on commit 1cd808a

Please sign in to comment.