diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:26:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:26:02 +0000 |
commit | fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3 (patch) | |
tree | 84c735df2e97350a721273e9dd425729d43cc8a2 /vendor/textalk/websocket/tests/mock/EchoLog.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-pdfexport-fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3.tar.xz icingaweb2-module-pdfexport-fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3.zip |
Adding upstream version 0.10.2+dfsg1.upstream/0.10.2+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/textalk/websocket/tests/mock/EchoLog.php')
-rw-r--r-- | vendor/textalk/websocket/tests/mock/EchoLog.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/textalk/websocket/tests/mock/EchoLog.php b/vendor/textalk/websocket/tests/mock/EchoLog.php new file mode 100644 index 0000000..369131a --- /dev/null +++ b/vendor/textalk/websocket/tests/mock/EchoLog.php @@ -0,0 +1,34 @@ +<?php + +/** + * Simple echo logger (only available when running in dev environment) + */ + +namespace WebSocket; + +class EchoLog implements \Psr\Log\LoggerInterface +{ + use \Psr\Log\LoggerTrait; + + public function log($level, $message, array $context = []) + { + $message = $this->interpolate($message, $context); + $context_string = empty($context) ? '' : json_encode($context); + echo str_pad($level, 8) . " | {$message} {$context_string}\n"; + } + + public function interpolate($message, array $context = []) + { + // Build a replacement array with braces around the context keys + $replace = []; + foreach ($context as $key => $val) { + // Check that the value can be cast to string + if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) { + $replace['{' . $key . '}'] = $val; + } + } + + // Interpolate replacement values into the message and return + return strtr($message, $replace); + } +} |