mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-01 10:50:21 +02:00
Allow use of formatted message
This change allows you to use the "formatted" index from your formatter. This is helpful if you want to create a formatter that would include *some* context information beyond the message itself. Since the default `LineFormatter` would be too verbose, I added a `useFormattedMessage()` method that accepts a boolean and would turn the use of the formatter on or off. This way, if you want to use a custom formatter, you can enable the functionality...but it will still work the same out of the box otherwise with just the message getting sent to Pushover.
This commit is contained in:
@@ -30,6 +30,7 @@ class PushoverHandler extends SocketHandler
|
||||
|
||||
private $highPriorityLevel;
|
||||
private $emergencyLevel;
|
||||
private $useFormattedMessage = false;
|
||||
|
||||
/**
|
||||
* All parameters that can be sent to Pushover
|
||||
@@ -103,7 +104,10 @@ class PushoverHandler extends SocketHandler
|
||||
{
|
||||
// Pushover has a limit of 512 characters on title and message combined.
|
||||
$maxMessageLength = 512 - strlen($this->title);
|
||||
$message = substr($record['message'], 0, $maxMessageLength);
|
||||
|
||||
$message = ($this->useFormattedMessage) ? $record['formatted'] : $record['message'];
|
||||
$message = substr($message, 0, $maxMessageLength);
|
||||
|
||||
$timestamp = $record['datetime']->getTimestamp();
|
||||
|
||||
$dataArray = array(
|
||||
@@ -169,4 +173,13 @@ class PushoverHandler extends SocketHandler
|
||||
{
|
||||
$this->emergencyLevel = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the formatted message?
|
||||
* @param boolean $value
|
||||
*/
|
||||
public function useFormattedMessage($value)
|
||||
{
|
||||
$this->useFormattedMessage = (bool) $value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user