From 5a00504b08cd4274bd8f87ef2fb77ec7700f4224 Mon Sep 17 00:00:00 2001 From: DJ Sipe Date: Thu, 9 Apr 2015 15:58:16 -0400 Subject: [PATCH] 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. --- src/Monolog/Handler/PushoverHandler.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/PushoverHandler.php b/src/Monolog/Handler/PushoverHandler.php index cd2fcfa3..6ab115c7 100644 --- a/src/Monolog/Handler/PushoverHandler.php +++ b/src/Monolog/Handler/PushoverHandler.php @@ -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; + } }