Skip to content

Commit 5ae198b

Browse files
authored
Update RollbarLoggingHandler.php
1 parent ded0849 commit 5ae198b

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/Logger/RollbarLoggingHandler.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace SimpleSAML\Module\rollbar\Logger;
64

75
use Rollbar\Payload\Level as RollbarLogLevel;
86
use Rollbar\Rollbar;
97
use SimpleSAML\Configuration;
108
use SimpleSAML\Logger;
9+
use SimpleSAML\Logger\LoggingHandlerInterface;
1110

1211
/**
1312
* A class for logging to the default php error log.
@@ -85,8 +84,6 @@ public function __construct(Configuration $config)
8584
* Initialize rollbar object.
8685
*/
8786
protected function init() {
88-
$environment = $this->config->get('environment');
89-
9087
if (empty($this->token) || empty($this->environment)) {
9188
return FALSE;
9289
}
@@ -122,15 +119,17 @@ public function setLogFormat(string $format): void
122119
*/
123120
public function log(int $level, string $string): void
124121
{
122+
$levelName = self::$levelMap[$level] ?? sprintf('UNKNOWN%d', $level);
125123
if (!$this->init()) {
126124
return;
127125
}
128126

129-
$formats = ['%process'];
130-
$replacements = [$this->processname];
127+
$formats = ['%process', '%level'];
128+
$replacements = [$this->processname, strtoupper($levelName)];
131129
$string = str_replace($formats, $replacements, $string);
130+
$string = preg_replace('/^%date(\{[^\}]+\})?\s*/', '', $string);
132131
$string = trim($string);
133132

134-
Rollbar::log(self::$levelMap[$level] ?? sprintf('UNKNOWN%d', $level), $string);
133+
Rollbar::log($levelName, $string);
135134
}
136135
}

0 commit comments

Comments
 (0)