From 3bd2e098a23fa88ec576989227e798f8ce2c0987 Mon Sep 17 00:00:00 2001 From: Adi Priyanto Date: Thu, 17 Aug 2017 23:18:14 +0700 Subject: [PATCH 1/2] truncate very long message --- src/Target.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Target.php b/src/Target.php index 89d82d8..321cf61 100644 --- a/src/Target.php +++ b/src/Target.php @@ -12,6 +12,7 @@ use sergeymakinen\yii\logmessage\Message; use yii\base\InvalidValueException; use yii\di\Instance; +use yii\helpers\StringHelper; use yii\httpclient\Client; use yii\log\Logger; @@ -71,6 +72,11 @@ class Target extends \yii\log\Target Logger::LEVEL_TRACE => '📝', ]; + /** + * @var int max character in message text. + */ + public $messageMaxLength = 3000; + /** * @inheritDoc */ @@ -234,7 +240,7 @@ private function substitute($name, Message $message) if ($config['short']) { $value = '`' . $value . '`'; } else { - $value = "```text\n" . $value . "\n```"; + $value = "```text\n" . StringHelper::truncate($value, $this->messageMaxLength) . "\n```"; } } if (isset($config['title'])) { From a1d53897e9409715000e34834503f77285884df1 Mon Sep 17 00:00:00 2001 From: Adi Priyanto Date: Fri, 18 Aug 2017 01:12:17 +0700 Subject: [PATCH 2/2] change variable name and truncate all 'wrapAsCode' messages --- src/Target.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Target.php b/src/Target.php index 321cf61..51f0fc5 100644 --- a/src/Target.php +++ b/src/Target.php @@ -75,7 +75,7 @@ class Target extends \yii\log\Target /** * @var int max character in message text. */ - public $messageMaxLength = 3000; + public $substitutionMaxLength = 3000; /** * @inheritDoc @@ -237,10 +237,11 @@ private function substitute($name, Message $message) } if ($config['wrapAsCode']) { + $value = StringHelper::truncate($value, $this->substitutionMaxLength); if ($config['short']) { $value = '`' . $value . '`'; } else { - $value = "```text\n" . StringHelper::truncate($value, $this->messageMaxLength) . "\n```"; + $value = "```text\n" . $value . "\n```"; } } if (isset($config['title'])) {