mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 13:16:39 +02:00
Use @return $this
where applicable (#1828)
This commit is contained in:
@@ -63,7 +63,7 @@ class ErrorHandler
|
||||
* @param array<int, LogLevel::*>|false $errorLevelMap an array of E_* constant to LogLevel::* constant mapping, or false to disable error handling
|
||||
* @param array<class-string, LogLevel::*>|false $exceptionLevelMap an array of class name to LogLevel::* constant mapping, or false to disable exception handling
|
||||
* @param LogLevel::*|null|false $fatalLevel a LogLevel::* constant, null to use the default LogLevel::ALERT or false to disable fatal error handling
|
||||
* @return ErrorHandler
|
||||
* @return static
|
||||
*/
|
||||
public static function register(LoggerInterface $logger, $errorLevelMap = [], $exceptionLevelMap = [], $fatalLevel = null): self
|
||||
{
|
||||
@@ -126,6 +126,7 @@ class ErrorHandler
|
||||
/**
|
||||
* @param LogLevel::*|null $level a LogLevel::* constant, null to use the default LogLevel::ALERT
|
||||
* @param int $reservedMemorySize Amount of KBs to reserve in memory so that it can be freed when handling fatal errors giving Monolog some room in memory to get its job done
|
||||
* @return $this
|
||||
*/
|
||||
public function registerFatalHandler($level = null, int $reservedMemorySize = 20): self
|
||||
{
|
||||
|
@@ -107,6 +107,9 @@ class JsonFormatter extends NormalizerFormatter
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function includeStacktraces(bool $include = true): self
|
||||
{
|
||||
$this->includeStacktraces = $include;
|
||||
|
@@ -49,6 +49,9 @@ class LineFormatter extends NormalizerFormatter
|
||||
parent::__construct($dateFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function includeStacktraces(bool $include = true, ?Closure $parser = null): self
|
||||
{
|
||||
$this->includeStacktraces = $include;
|
||||
@@ -60,6 +63,9 @@ class LineFormatter extends NormalizerFormatter
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function allowInlineLineBreaks(bool $allow = true): self
|
||||
{
|
||||
$this->allowInlineLineBreaks = $allow;
|
||||
@@ -67,6 +73,9 @@ class LineFormatter extends NormalizerFormatter
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function ignoreEmptyContextAndExtra(bool $ignore = true): self
|
||||
{
|
||||
$this->ignoreEmptyContextAndExtra = $ignore;
|
||||
|
@@ -26,6 +26,9 @@ class LogmaticFormatter extends JsonFormatter
|
||||
|
||||
protected string $appName = '';
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setHostname(string $hostname): self
|
||||
{
|
||||
$this->hostname = $hostname;
|
||||
@@ -33,6 +36,9 @@ class LogmaticFormatter extends JsonFormatter
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setAppName(string $appName): self
|
||||
{
|
||||
$this->appName = $appName;
|
||||
|
@@ -154,7 +154,6 @@ class MongoDBFormatter implements FormatterInterface
|
||||
? (int) $milliseconds
|
||||
: (string) $milliseconds;
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
return new UTCDateTime($milliseconds);
|
||||
}
|
||||
}
|
||||
|
@@ -78,6 +78,9 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $this->dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setDateFormat(string $dateFormat): self
|
||||
{
|
||||
$this->dateFormat = $dateFormat;
|
||||
@@ -93,6 +96,9 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $this->maxNormalizeDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setMaxNormalizeDepth(int $maxNormalizeDepth): self
|
||||
{
|
||||
$this->maxNormalizeDepth = $maxNormalizeDepth;
|
||||
@@ -108,6 +114,9 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $this->maxNormalizeItemCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setMaxNormalizeItemCount(int $maxNormalizeItemCount): self
|
||||
{
|
||||
$this->maxNormalizeItemCount = $maxNormalizeItemCount;
|
||||
@@ -117,6 +126,8 @@ class NormalizerFormatter implements FormatterInterface
|
||||
|
||||
/**
|
||||
* Enables `json_encode` pretty print.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setJsonPrettyPrint(bool $enable): self
|
||||
{
|
||||
@@ -289,6 +300,9 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $date->format($this->dateFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addJsonEncodeOption(int $option): self
|
||||
{
|
||||
$this->jsonEncodeOptions |= $option;
|
||||
@@ -296,6 +310,9 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function removeJsonEncodeOption(int $option): self
|
||||
{
|
||||
$this->jsonEncodeOptions &= ~$option;
|
||||
|
@@ -51,6 +51,7 @@ abstract class AbstractHandler extends Handler implements ResettableInterface
|
||||
* Sets minimum logging level at which this handler will be triggered.
|
||||
*
|
||||
* @param Level|LogLevel::* $level Level or level name
|
||||
* @return $this
|
||||
*
|
||||
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
|
||||
*/
|
||||
@@ -74,6 +75,7 @@ abstract class AbstractHandler extends Handler implements ResettableInterface
|
||||
*
|
||||
* @param bool $bubble true means that this handler allows bubbling.
|
||||
* false means that bubbling is not permitted.
|
||||
* @return $this
|
||||
*/
|
||||
public function setBubble(bool $bubble): self
|
||||
{
|
||||
|
@@ -80,6 +80,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
|
||||
/**
|
||||
* @param int|string|Level|LogLevel::*|array<int|string|Level|LogLevel::*> $minLevelOrList A list of levels to accept or a minimum level or level name if maxLevel is provided
|
||||
* @param int|string|Level|LogLevel::* $maxLevel Maximum level or level name to accept, only used if $minLevelOrList is not an array
|
||||
* @return $this
|
||||
*
|
||||
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::*|array<value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::*> $minLevelOrList
|
||||
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $maxLevel
|
||||
|
@@ -89,6 +89,7 @@ class LogglyHandler extends AbstractProcessingHandler
|
||||
|
||||
/**
|
||||
* @param string[]|string $tag
|
||||
* @return $this
|
||||
*/
|
||||
public function setTag(string|array $tag): self
|
||||
{
|
||||
@@ -103,6 +104,7 @@ class LogglyHandler extends AbstractProcessingHandler
|
||||
|
||||
/**
|
||||
* @param string[]|string $tag
|
||||
* @return $this
|
||||
*/
|
||||
public function addTag(string|array $tag): self
|
||||
{
|
||||
|
@@ -79,6 +79,7 @@ class NativeMailerHandler extends MailHandler
|
||||
* Add headers to the message
|
||||
*
|
||||
* @param string|string[] $headers Custom added headers
|
||||
* @return $this
|
||||
*/
|
||||
public function addHeader($headers): self
|
||||
{
|
||||
@@ -96,6 +97,7 @@ class NativeMailerHandler extends MailHandler
|
||||
* Add parameters to the message
|
||||
*
|
||||
* @param string|string[] $parameters Custom added parameters
|
||||
* @return $this
|
||||
*/
|
||||
public function addParameter($parameters): self
|
||||
{
|
||||
@@ -142,6 +144,7 @@ class NativeMailerHandler extends MailHandler
|
||||
|
||||
/**
|
||||
* @param string $contentType The content type of the email - Defaults to text/plain. Use text/html for HTML messages.
|
||||
* @return $this
|
||||
*/
|
||||
public function setContentType(string $contentType): self
|
||||
{
|
||||
@@ -154,6 +157,9 @@ class NativeMailerHandler extends MailHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoding(string $encoding): self
|
||||
{
|
||||
if (strpos($encoding, "\n") !== false || strpos($encoding, "\r") !== false) {
|
||||
|
@@ -208,6 +208,7 @@ class PushoverHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* @param int|string|Level|LogLevel::* $level
|
||||
* @return $this
|
||||
*
|
||||
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
|
||||
*/
|
||||
@@ -220,6 +221,7 @@ class PushoverHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* @param int|string|Level|LogLevel::* $level
|
||||
* @return $this
|
||||
*
|
||||
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
|
||||
*/
|
||||
@@ -232,6 +234,8 @@ class PushoverHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* Use the formatted message?
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function useFormattedMessage(bool $useFormattedMessage): self
|
||||
{
|
||||
|
@@ -77,6 +77,9 @@ class RotatingFileHandler extends StreamHandler
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilenameFormat(string $filenameFormat, string $dateFormat): self
|
||||
{
|
||||
$this->setDateFormat($dateFormat);
|
||||
|
@@ -221,8 +221,7 @@ class SlackRecord
|
||||
* Channel used by the bot when posting
|
||||
*
|
||||
* @param ?string $channel
|
||||
*
|
||||
* @return static
|
||||
* @return $this
|
||||
*/
|
||||
public function setChannel(?string $channel = null): self
|
||||
{
|
||||
@@ -235,8 +234,7 @@ class SlackRecord
|
||||
* Username used by the bot when posting
|
||||
*
|
||||
* @param ?string $username
|
||||
*
|
||||
* @return static
|
||||
* @return $this
|
||||
*/
|
||||
public function setUsername(?string $username = null): self
|
||||
{
|
||||
@@ -245,6 +243,9 @@ class SlackRecord
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function useAttachment(bool $useAttachment = true): self
|
||||
{
|
||||
$this->useAttachment = $useAttachment;
|
||||
@@ -252,6 +253,9 @@ class SlackRecord
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setUserIcon(?string $userIcon = null): self
|
||||
{
|
||||
$this->userIcon = $userIcon;
|
||||
@@ -263,6 +267,9 @@ class SlackRecord
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function useShortAttachment(bool $useShortAttachment = false): self
|
||||
{
|
||||
$this->useShortAttachment = $useShortAttachment;
|
||||
@@ -270,6 +277,9 @@ class SlackRecord
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function includeContextAndExtra(bool $includeContextAndExtra = false): self
|
||||
{
|
||||
$this->includeContextAndExtra = $includeContextAndExtra;
|
||||
@@ -283,6 +293,7 @@ class SlackRecord
|
||||
|
||||
/**
|
||||
* @param string[] $excludeFields
|
||||
* @return $this
|
||||
*/
|
||||
public function excludeFields(array $excludeFields = []): self
|
||||
{
|
||||
@@ -291,6 +302,9 @@ class SlackRecord
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setFormatter(?FormatterInterface $formatter = null): self
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
|
@@ -192,6 +192,8 @@ class SlackHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* Channel used by the bot when posting
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setChannel(string $channel): self
|
||||
{
|
||||
@@ -202,6 +204,8 @@ class SlackHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* Username used by the bot when posting
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUsername(string $username): self
|
||||
{
|
||||
@@ -210,6 +214,9 @@ class SlackHandler extends SocketHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function useAttachment(bool $useAttachment): self
|
||||
{
|
||||
$this->slackRecord->useAttachment($useAttachment);
|
||||
@@ -217,6 +224,9 @@ class SlackHandler extends SocketHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setIconEmoji(string $iconEmoji): self
|
||||
{
|
||||
$this->slackRecord->setUserIcon($iconEmoji);
|
||||
@@ -224,6 +234,9 @@ class SlackHandler extends SocketHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function useShortAttachment(bool $useShortAttachment): self
|
||||
{
|
||||
$this->slackRecord->useShortAttachment($useShortAttachment);
|
||||
@@ -231,6 +244,9 @@ class SlackHandler extends SocketHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function includeContextAndExtra(bool $includeContextAndExtra): self
|
||||
{
|
||||
$this->slackRecord->includeContextAndExtra($includeContextAndExtra);
|
||||
@@ -240,6 +256,7 @@ class SlackHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* @param string[] $excludeFields
|
||||
* @return $this
|
||||
*/
|
||||
public function excludeFields(array $excludeFields): self
|
||||
{
|
||||
|
@@ -110,6 +110,8 @@ class SocketHandler extends AbstractProcessingHandler
|
||||
|
||||
/**
|
||||
* Set socket connection to be persistent. It only has effect before the connection is initiated.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPersistent(bool $persistent): self
|
||||
{
|
||||
@@ -122,6 +124,7 @@ class SocketHandler extends AbstractProcessingHandler
|
||||
* Set connection timeout. Only has effect before we connect.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.fsockopen.php
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnectionTimeout(float $seconds): self
|
||||
{
|
||||
@@ -135,6 +138,7 @@ class SocketHandler extends AbstractProcessingHandler
|
||||
* Set write timeout. Only has effect before we connect.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.stream-set-timeout.php
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimeout(float $seconds): self
|
||||
{
|
||||
@@ -148,6 +152,7 @@ class SocketHandler extends AbstractProcessingHandler
|
||||
* Set writing timeout. Only has effect during connection in the writing cycle.
|
||||
*
|
||||
* @param float $seconds 0 for no timeout
|
||||
* @return $this
|
||||
*/
|
||||
public function setWritingTimeout(float $seconds): self
|
||||
{
|
||||
@@ -159,6 +164,8 @@ class SocketHandler extends AbstractProcessingHandler
|
||||
|
||||
/**
|
||||
* Set chunk size. Only has effect during connection in the writing cycle.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setChunkSize(int $bytes): self
|
||||
{
|
||||
|
@@ -142,6 +142,8 @@ class SyslogUdpHandler extends AbstractSyslogHandler
|
||||
|
||||
/**
|
||||
* Inject your own socket, mainly used for testing
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSocket(UdpSocket $socket): self
|
||||
{
|
||||
|
@@ -130,6 +130,9 @@ class TelegramBotHandler extends AbstractProcessingHandler
|
||||
$this->setTopic($topic);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setParseMode(string $parseMode = null): self
|
||||
{
|
||||
if ($parseMode !== null && !in_array($parseMode, self::AVAILABLE_PARSE_MODES, true)) {
|
||||
@@ -141,6 +144,9 @@ class TelegramBotHandler extends AbstractProcessingHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function disableWebPagePreview(bool $disableWebPagePreview = null): self
|
||||
{
|
||||
$this->disableWebPagePreview = $disableWebPagePreview;
|
||||
@@ -148,6 +154,9 @@ class TelegramBotHandler extends AbstractProcessingHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function disableNotification(bool $disableNotification = null): self
|
||||
{
|
||||
$this->disableNotification = $disableNotification;
|
||||
@@ -158,6 +167,7 @@ class TelegramBotHandler extends AbstractProcessingHandler
|
||||
/**
|
||||
* True - split a message longer than MAX_MESSAGE_LENGTH into parts and send in multiple messages.
|
||||
* False - truncates a message that is too long.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function splitLongMessages(bool $splitLongMessages = false): self
|
||||
@@ -169,6 +179,7 @@ class TelegramBotHandler extends AbstractProcessingHandler
|
||||
|
||||
/**
|
||||
* Adds 1-second delay between sending a split message (according to Telegram API to avoid 429 Too Many Requests).
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delayBetweenMessages(bool $delayBetweenMessages = false): self
|
||||
@@ -178,6 +189,9 @@ class TelegramBotHandler extends AbstractProcessingHandler
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTopic(int $topic = null): self
|
||||
{
|
||||
$this->topic = $topic;
|
||||
|
@@ -188,6 +188,8 @@ class Logger implements LoggerInterface, ResettableInterface
|
||||
|
||||
/**
|
||||
* Return a new cloned instance with the name changed
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withName(string $name): self
|
||||
{
|
||||
@@ -199,6 +201,8 @@ class Logger implements LoggerInterface, ResettableInterface
|
||||
|
||||
/**
|
||||
* Pushes a handler on to the stack.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function pushHandler(HandlerInterface $handler): self
|
||||
{
|
||||
@@ -227,6 +231,7 @@ class Logger implements LoggerInterface, ResettableInterface
|
||||
* If a map is passed, keys will be ignored.
|
||||
*
|
||||
* @param list<HandlerInterface> $handlers
|
||||
* @return $this
|
||||
*/
|
||||
public function setHandlers(array $handlers): self
|
||||
{
|
||||
@@ -250,6 +255,7 @@ class Logger implements LoggerInterface, ResettableInterface
|
||||
* Adds a processor on to the stack.
|
||||
*
|
||||
* @phpstan-param ProcessorInterface|(callable(LogRecord): LogRecord) $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function pushProcessor(ProcessorInterface|callable $callback): self
|
||||
{
|
||||
@@ -292,6 +298,7 @@ class Logger implements LoggerInterface, ResettableInterface
|
||||
* to suppress microseconds from the output.
|
||||
*
|
||||
* @param bool $micro True to use microtime() to create timestamps
|
||||
* @return $this
|
||||
*/
|
||||
public function useMicrosecondTimestamps(bool $micro): self
|
||||
{
|
||||
@@ -300,6 +307,9 @@ class Logger implements LoggerInterface, ResettableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function useLoggingLoopDetection(bool $detectCycles): self
|
||||
{
|
||||
$this->detectCycles = $detectCycles;
|
||||
@@ -526,6 +536,8 @@ class Logger implements LoggerInterface, ResettableInterface
|
||||
* Set a custom exception handler that will be called if adding a new record fails
|
||||
*
|
||||
* The Closure will receive an exception object and the record that failed to be logged
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExceptionHandler(Closure|null $callback): self
|
||||
{
|
||||
@@ -673,6 +685,8 @@ class Logger implements LoggerInterface, ResettableInterface
|
||||
|
||||
/**
|
||||
* Sets the timezone to be used for the timestamp of log records.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimezone(DateTimeZone $tz): self
|
||||
{
|
||||
|
@@ -33,6 +33,7 @@ class TagProcessor implements ProcessorInterface
|
||||
|
||||
/**
|
||||
* @param string[] $tags
|
||||
* @return $this
|
||||
*/
|
||||
public function addTags(array $tags = []): self
|
||||
{
|
||||
@@ -43,6 +44,7 @@ class TagProcessor implements ProcessorInterface
|
||||
|
||||
/**
|
||||
* @param string[] $tags
|
||||
* @return $this
|
||||
*/
|
||||
public function setTags(array $tags = []): self
|
||||
{
|
||||
|
@@ -90,6 +90,9 @@ class WebProcessor implements ProcessorInterface
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addExtraField(string $extraName, string $serverName): self
|
||||
{
|
||||
$this->extraFields[$extraName] = $serverName;
|
||||
|
Reference in New Issue
Block a user