|
1 | 1 | <?php |
2 | 2 |
|
3 | | -declare(strict_types=1); |
4 | | - |
5 | 3 | namespace SimpleSAML\Module\rollbar\Logger; |
6 | 4 |
|
7 | 5 | use Rollbar\Payload\Level as RollbarLogLevel; |
8 | 6 | use Rollbar\Rollbar; |
9 | 7 | use SimpleSAML\Configuration; |
10 | 8 | use SimpleSAML\Logger; |
| 9 | +use SimpleSAML\Logger\LoggingHandlerInterface; |
11 | 10 |
|
12 | 11 | /** |
13 | 12 | * A class for logging to the default php error log. |
@@ -85,8 +84,6 @@ public function __construct(Configuration $config) |
85 | 84 | * Initialize rollbar object. |
86 | 85 | */ |
87 | 86 | protected function init() { |
88 | | - $environment = $this->config->get('environment'); |
89 | | - |
90 | 87 | if (empty($this->token) || empty($this->environment)) { |
91 | 88 | return FALSE; |
92 | 89 | } |
@@ -122,15 +119,17 @@ public function setLogFormat(string $format): void |
122 | 119 | */ |
123 | 120 | public function log(int $level, string $string): void |
124 | 121 | { |
| 122 | + $levelName = self::$levelMap[$level] ?? sprintf('UNKNOWN%d', $level); |
125 | 123 | if (!$this->init()) { |
126 | 124 | return; |
127 | 125 | } |
128 | 126 |
|
129 | | - $formats = ['%process']; |
130 | | - $replacements = [$this->processname]; |
| 127 | + $formats = ['%process', '%level']; |
| 128 | + $replacements = [$this->processname, strtoupper($levelName)]; |
131 | 129 | $string = str_replace($formats, $replacements, $string); |
| 130 | + $string = preg_replace('/^%date(\{[^\}]+\})?\s*/', '', $string); |
132 | 131 | $string = trim($string); |
133 | 132 |
|
134 | | - Rollbar::log(self::$levelMap[$level] ?? sprintf('UNKNOWN%d', $level), $string); |
| 133 | + Rollbar::log($levelName, $string); |
135 | 134 | } |
136 | 135 | } |
0 commit comments