Skip to content

Commit

Permalink
Merge pull request #119 from fcastilloes/log-limit
Browse files Browse the repository at this point in the history
Limit the log output
  • Loading branch information
fcastilloes authored Mar 3, 2022
2 parents bcf8f4b + eb4c5da commit 8ff77cf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Logger/KatanaLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ abstract class KatanaLogger
self::LOG_NONE => 'NONE',
];

const MAX_LOG_LENGTH = 65535;
const LOG_TRUNCATE_REPLACEMENT = '... (truncated)';

/**
* @var int
*/
Expand Down Expand Up @@ -87,7 +90,15 @@ protected function log(int $level, string $message)
return;
}

echo $this->formatMessage($level, $message), "\n";
$log = $this->formatMessage($level, '{{message}}');
$logLength = strlen($log) + strlen($message) - 11;

if ($logLength > self::MAX_LOG_LENGTH) {
$messageExcessLength = self::MAX_LOG_LENGTH - $logLength - strlen(self::LOG_TRUNCATE_REPLACEMENT);
$message = substr($message, 0, $messageExcessLength) . self::LOG_TRUNCATE_REPLACEMENT;
}

echo str_replace('{{message}}', $message, $log), "\n";
}

/**
Expand Down

0 comments on commit 8ff77cf

Please sign in to comment.