summaryrefslogtreecommitdiffstats
path: root/vendor/textalk/websocket/tests/mock/EchoLog.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/textalk/websocket/tests/mock/EchoLog.php')
-rw-r--r--vendor/textalk/websocket/tests/mock/EchoLog.php34
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);
+ }
+}