1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 12:47:39 +02:00

Tweak const visibility, refs #1228

This commit is contained in:
Jordi Boggiano
2018-11-29 20:05:19 +01:00
parent a7984a640f
commit bb99e4c699
16 changed files with 48 additions and 55 deletions

View File

@@ -22,7 +22,7 @@ use Gelf\Message;
*/ */
class GelfMessageFormatter extends NormalizerFormatter class GelfMessageFormatter extends NormalizerFormatter
{ {
public const DEFAULT_MAX_LENGTH = 32766; protected const DEFAULT_MAX_LENGTH = 32766;
/** /**
* @var string the name of the system for the Gelf log message * @var string the name of the system for the Gelf log message

View File

@@ -18,7 +18,7 @@ namespace Monolog\Formatter;
*/ */
class LogmaticFormatter extends JsonFormatter class LogmaticFormatter extends JsonFormatter
{ {
public const MARKERS = ["sourcecode", "php"]; protected const MARKERS = ["sourcecode", "php"];
/** /**
* @var string * @var string
@@ -59,7 +59,7 @@ class LogmaticFormatter extends JsonFormatter
$record["appname"] = $this->appname; $record["appname"] = $this->appname;
} }
$record["@marker"] = self::MARKERS; $record["@marker"] = static::MARKERS;
return parent::format($record); return parent::format($record);
} }

View File

@@ -22,8 +22,6 @@ use Monolog\Logger;
*/ */
class WildfireFormatter extends NormalizerFormatter class WildfireFormatter extends NormalizerFormatter
{ {
public const TABLE = 'table';
/** /**
* Translates Monolog log levels to Wildfire levels. * Translates Monolog log levels to Wildfire levels.
*/ */
@@ -69,10 +67,10 @@ class WildfireFormatter extends NormalizerFormatter
$message = reset($message); $message = reset($message);
} }
if (isset($record['context'][self::TABLE])) { if (isset($record['context']['table'])) {
$type = 'TABLE'; $type = 'TABLE';
$label = $record['channel'] .': '. $record['message']; $label = $record['channel'] .': '. $record['message'];
$message = $record['context'][self::TABLE]; $message = $record['context']['table'];
} else { } else {
$type = $this->logLevels[$record['level']]; $type = $this->logLevels[$record['level']];
$label = $record['channel']; $label = $record['channel'];

View File

@@ -29,17 +29,17 @@ class ChromePHPHandler extends AbstractProcessingHandler
/** /**
* Version of the extension * Version of the extension
*/ */
public const VERSION = '4.0'; protected const VERSION = '4.0';
/** /**
* Header name * Header name
*/ */
public const HEADER_NAME = 'X-ChromeLogger-Data'; protected const HEADER_NAME = 'X-ChromeLogger-Data';
/** /**
* Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+) * Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+)
*/ */
public const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|HeadlessChrome|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}'; protected const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|HeadlessChrome|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}';
protected static $initialized = false; protected static $initialized = false;
@@ -164,7 +164,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
} }
if (trim($data) !== '') { if (trim($data) !== '') {
$this->sendHeader(self::HEADER_NAME, $data); $this->sendHeader(static::HEADER_NAME, $data);
} }
} }
@@ -187,6 +187,6 @@ class ChromePHPHandler extends AbstractProcessingHandler
return false; return false;
} }
return preg_match(self::USER_AGENT_REGEX, $_SERVER['HTTP_USER_AGENT']) === 1; return preg_match(static::USER_AGENT_REGEX, $_SERVER['HTTP_USER_AGENT']) === 1;
} }
} }

View File

@@ -26,22 +26,22 @@ class FirePHPHandler extends AbstractProcessingHandler
/** /**
* WildFire JSON header message format * WildFire JSON header message format
*/ */
public const PROTOCOL_URI = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2'; protected const PROTOCOL_URI = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
/** /**
* FirePHP structure for parsing messages & their presentation * FirePHP structure for parsing messages & their presentation
*/ */
public const STRUCTURE_URI = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'; protected const STRUCTURE_URI = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
/** /**
* Must reference a "known" plugin, otherwise headers won't display in FirePHP * Must reference a "known" plugin, otherwise headers won't display in FirePHP
*/ */
public const PLUGIN_URI = 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3'; protected const PLUGIN_URI = 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3';
/** /**
* Header prefix for Wildfire to recognize & parse headers * Header prefix for Wildfire to recognize & parse headers
*/ */
public const HEADER_PREFIX = 'X-Wf'; protected const HEADER_PREFIX = 'X-Wf';
/** /**
* Whether or not Wildfire vendor-specific headers have been generated & sent yet * Whether or not Wildfire vendor-specific headers have been generated & sent yet
@@ -65,7 +65,7 @@ class FirePHPHandler extends AbstractProcessingHandler
*/ */
protected function createHeader(array $meta, string $message): array protected function createHeader(array $meta, string $message): array
{ {
$header = sprintf('%s-%s', self::HEADER_PREFIX, join('-', $meta)); $header = sprintf('%s-%s', static::HEADER_PREFIX, join('-', $meta));
return [$header => $message]; return [$header => $message];
} }
@@ -103,9 +103,9 @@ class FirePHPHandler extends AbstractProcessingHandler
{ {
// Initial payload consists of required headers for Wildfire // Initial payload consists of required headers for Wildfire
return array_merge( return array_merge(
$this->createHeader(['Protocol', 1], self::PROTOCOL_URI), $this->createHeader(['Protocol', 1], static::PROTOCOL_URI),
$this->createHeader([1, 'Structure', 1], self::STRUCTURE_URI), $this->createHeader([1, 'Structure', 1], static::STRUCTURE_URI),
$this->createHeader([1, 'Plugin', 1], self::PLUGIN_URI) $this->createHeader([1, 'Plugin', 1], static::PLUGIN_URI)
); );
} }

View File

@@ -25,9 +25,9 @@ use Monolog\Logger;
*/ */
class FleepHookHandler extends SocketHandler class FleepHookHandler extends SocketHandler
{ {
public const FLEEP_HOST = 'fleep.io'; protected const FLEEP_HOST = 'fleep.io';
public const FLEEP_HOOK_URI = '/hook/'; protected const FLEEP_HOOK_URI = '/hook/';
/** /**
* @var string Webhook token (specifies the conversation where logs are sent) * @var string Webhook token (specifies the conversation where logs are sent)
@@ -53,7 +53,7 @@ class FleepHookHandler extends SocketHandler
$this->token = $token; $this->token = $token;
$connectionString = 'ssl://' . self::FLEEP_HOST . ':443'; $connectionString = 'ssl://' . static::FLEEP_HOST . ':443';
parent::__construct($connectionString, $level, $bubble); parent::__construct($connectionString, $level, $bubble);
} }
@@ -93,8 +93,8 @@ class FleepHookHandler extends SocketHandler
*/ */
private function buildHeader(string $content): string private function buildHeader(string $content): string
{ {
$header = "POST " . self::FLEEP_HOOK_URI . $this->token . " HTTP/1.1\r\n"; $header = "POST " . static::FLEEP_HOOK_URI . $this->token . " HTTP/1.1\r\n";
$header .= "Host: " . self::FLEEP_HOST . "\r\n"; $header .= "Host: " . static::FLEEP_HOST . "\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($content) . "\r\n"; $header .= "Content-Length: " . strlen($content) . "\r\n";
$header .= "\r\n"; $header .= "\r\n";

View File

@@ -29,15 +29,10 @@ use Monolog\Logger;
*/ */
class HipChatHandler extends SocketHandler class HipChatHandler extends SocketHandler
{ {
/**
* The maximum allowed length for the name used in the "from" field.
*/
public const MAXIMUM_NAME_LENGTH = 15;
/** /**
* The maximum allowed length for the message. * The maximum allowed length for the message.
*/ */
public const MAXIMUM_MESSAGE_LENGTH = 9500; protected const MAXIMUM_MESSAGE_LENGTH = 9500;
/** /**
* @var string * @var string

View File

@@ -24,9 +24,9 @@ use Monolog\Formatter\LogglyFormatter;
*/ */
class LogglyHandler extends AbstractProcessingHandler class LogglyHandler extends AbstractProcessingHandler
{ {
public const HOST = 'logs-01.loggly.com'; protected const HOST = 'logs-01.loggly.com';
public const ENDPOINT_SINGLE = 'inputs'; protected const ENDPOINT_SINGLE = 'inputs';
public const ENDPOINT_BATCH = 'bulk'; protected const ENDPOINT_BATCH = 'bulk';
protected $token; protected $token;
@@ -76,7 +76,7 @@ class LogglyHandler extends AbstractProcessingHandler
protected function write(array $record): void protected function write(array $record): void
{ {
$this->send($record["formatted"], self::ENDPOINT_SINGLE); $this->send($record["formatted"], static::ENDPOINT_SINGLE);
} }
public function handleBatch(array $records): void public function handleBatch(array $records): void
@@ -88,13 +88,13 @@ class LogglyHandler extends AbstractProcessingHandler
}); });
if ($records) { if ($records) {
$this->send($this->getFormatter()->formatBatch($records), self::ENDPOINT_BATCH); $this->send($this->getFormatter()->formatBatch($records), static::ENDPOINT_BATCH);
} }
} }
protected function send(string $data, string $endpoint): void protected function send(string $data, string $endpoint): void
{ {
$url = sprintf("https://%s/%s/%s/", self::HOST, $endpoint, $this->token); $url = sprintf("https://%s/%s/%s/", static::HOST, $endpoint, $this->token);
$headers = ['Content-Type: application/json']; $headers = ['Content-Type: application/json'];

View File

@@ -51,7 +51,7 @@ class ProcessHandler extends AbstractProcessingHandler
/** /**
* @var array * @var array
*/ */
public const DESCRIPTOR_SPEC = [ protected const DESCRIPTOR_SPEC = [
0 => ['pipe', 'r'], // STDIN is a pipe that the child will read from 0 => ['pipe', 'r'], // STDIN is a pipe that the child will read from
1 => ['pipe', 'w'], // STDOUT is a pipe that the child will write to 1 => ['pipe', 'w'], // STDOUT is a pipe that the child will write to
2 => ['pipe', 'w'], // STDERR is a pipe to catch the any errors 2 => ['pipe', 'w'], // STDERR is a pipe to catch the any errors
@@ -115,7 +115,7 @@ class ProcessHandler extends AbstractProcessingHandler
*/ */
private function startProcess(): void private function startProcess(): void
{ {
$this->process = proc_open($this->command, self::DESCRIPTOR_SPEC, $this->pipes, $this->cwd); $this->process = proc_open($this->command, static::DESCRIPTOR_SPEC, $this->pipes, $this->cwd);
foreach ($this->pipes as $pipe) { foreach ($this->pipes as $pipe) {
stream_set_blocking($pipe, false); stream_set_blocking($pipe, false);

View File

@@ -50,7 +50,7 @@ class RotatingFileHandler extends StreamHandler
$this->maxFiles = (int) $maxFiles; $this->maxFiles = (int) $maxFiles;
$this->nextRotation = new \DateTimeImmutable('tomorrow'); $this->nextRotation = new \DateTimeImmutable('tomorrow');
$this->filenameFormat = '{filename}-{date}'; $this->filenameFormat = '{filename}-{date}';
$this->dateFormat = self::FILE_PER_DAY; $this->dateFormat = static::FILE_PER_DAY;
parent::__construct($this->getTimedFilename(), $level, $bubble, $filePermission, $useLocking); parent::__construct($this->getTimedFilename(), $level, $bubble, $filePermission, $useLocking);
} }

View File

@@ -182,13 +182,13 @@ class SlackRecord
{ {
switch (true) { switch (true) {
case $level >= Logger::ERROR: case $level >= Logger::ERROR:
return self::COLOR_DANGER; return static::COLOR_DANGER;
case $level >= Logger::WARNING: case $level >= Logger::WARNING:
return self::COLOR_WARNING; return static::COLOR_WARNING;
case $level >= Logger::INFO: case $level >= Logger::INFO:
return self::COLOR_GOOD; return static::COLOR_GOOD;
default: default:
return self::COLOR_DEFAULT; return static::COLOR_DEFAULT;
} }
} }

View File

@@ -22,9 +22,9 @@ use Monolog\Logger;
class SqsHandler extends AbstractProcessingHandler class SqsHandler extends AbstractProcessingHandler
{ {
/** 256 KB in bytes - maximum message size in SQS */ /** 256 KB in bytes - maximum message size in SQS */
public const MAX_MESSAGE_SIZE = 262144; protected const MAX_MESSAGE_SIZE = 262144;
/** 100 KB in bytes - head message size for new error log */ /** 100 KB in bytes - head message size for new error log */
public const HEAD_MESSAGE_SIZE = 102400; protected const HEAD_MESSAGE_SIZE = 102400;
/** @var SqsClient */ /** @var SqsClient */
private $client; private $client;
@@ -51,8 +51,8 @@ class SqsHandler extends AbstractProcessingHandler
} }
$messageBody = $record['formatted']; $messageBody = $record['formatted'];
if (strlen($messageBody) >= self::MAX_MESSAGE_SIZE) { if (strlen($messageBody) >= static::MAX_MESSAGE_SIZE) {
$messageBody = substr($messageBody, 0, self::HEAD_MESSAGE_SIZE); $messageBody = substr($messageBody, 0, static::HEAD_MESSAGE_SIZE);
} }
$this->client->sendMessage([ $this->client->sendMessage([

View File

@@ -13,7 +13,7 @@ namespace Monolog\Handler\SyslogUdp;
class UdpSocket class UdpSocket
{ {
public const DATAGRAM_MAX_LENGTH = 65023; protected const DATAGRAM_MAX_LENGTH = 65023;
/** @var string */ /** @var string */
protected $ip; protected $ip;
@@ -52,7 +52,7 @@ class UdpSocket
protected function assembleMessage(string $line, string $header): string protected function assembleMessage(string $line, string $header): string
{ {
$chunkSize = self::DATAGRAM_MAX_LENGTH - strlen($header); $chunkSize = static::DATAGRAM_MAX_LENGTH - strlen($header);
return $header . substr($line, 0, $chunkSize); return $header . substr($line, 0, $chunkSize);
} }

View File

@@ -120,7 +120,7 @@ class WildfireFormatterTest extends \PHPUnit\Framework\TestCase
'level_name' => 'ERROR', 'level_name' => 'ERROR',
'channel' => 'table-channel', 'channel' => 'table-channel',
'context' => [ 'context' => [
WildfireFormatter::TABLE => [ 'table' => [
['col1', 'col2', 'col3'], ['col1', 'col2', 'col3'],
['val1', 'val2', 'val3'], ['val1', 'val2', 'val3'],
['foo1', 'foo2', 'foo3'], ['foo1', 'foo2', 'foo3'],

View File

@@ -39,7 +39,7 @@ class ChromePHPHandlerTest extends TestCase
$expected = [ $expected = [
'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode([ 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode([
'version' => ChromePHPHandler::VERSION, 'version' => '4.0',
'columns' => ['label', 'log', 'backtrace', 'type'], 'columns' => ['label', 'log', 'backtrace', 'type'],
'rows' => [ 'rows' => [
'test', 'test',
@@ -73,7 +73,7 @@ class ChromePHPHandlerTest extends TestCase
$expected = [ $expected = [
'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode([ 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode([
'version' => ChromePHPHandler::VERSION, 'version' => '4.0',
'columns' => ['label', 'log', 'backtrace', 'type'], 'columns' => ['label', 'log', 'backtrace', 'type'],
'rows' => [ 'rows' => [
[ [
@@ -116,7 +116,7 @@ class ChromePHPHandlerTest extends TestCase
$expected = [ $expected = [
'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode([ 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode([
'version' => ChromePHPHandler::VERSION, 'version' => '4.0',
'columns' => ['label', 'log', 'backtrace', 'type'], 'columns' => ['label', 'log', 'backtrace', 'type'],
'rows' => [ 'rows' => [
'test', 'test',

View File

@@ -80,6 +80,6 @@ class FleepHookHandlerTest extends TestCase
*/ */
public function testConnectionStringisConstructedCorrectly() public function testConnectionStringisConstructedCorrectly()
{ {
$this->assertEquals('ssl://' . FleepHookHandler::FLEEP_HOST . ':443', $this->handler->getConnectionString()); $this->assertEquals('ssl://fleep.io:443', $this->handler->getConnectionString());
} }
} }