|
9 | 9 | class DashboardLogger |
10 | 10 | { |
11 | 11 | const LOG_CHANNEL_PREFIX = 'private-websockets-dashboard-'; |
| 12 | + |
12 | 13 | const TYPE_DISCONNECTION = 'disconnection'; |
| 14 | + |
13 | 15 | const TYPE_CONNECTION = 'connection'; |
| 16 | + |
14 | 17 | const TYPE_VACATED = 'vacated'; |
| 18 | + |
15 | 19 | const TYPE_OCCUPIED = 'occupied'; |
| 20 | + |
16 | 21 | const TYPE_SUBSCRIBED = 'subscribed'; |
| 22 | + |
17 | 23 | const TYPE_CLIENT_MESSAGE = 'client-message'; |
| 24 | + |
18 | 25 | const TYPE_API_MESSAGE = 'api-message'; |
19 | 26 |
|
| 27 | + const TYPE_REPLICATOR_SUBSCRIBED = 'replicator-subscribed'; |
| 28 | + |
| 29 | + const TYPE_REPLICATOR_UNSUBSCRIBED = 'replicator-unsubscribed'; |
| 30 | + |
20 | 31 | public static function connection(ConnectionInterface $connection) |
21 | 32 | { |
22 | 33 | /** @var \GuzzleHttp\Psr7\Request $request */ |
23 | 34 | $request = $connection->httpRequest; |
24 | 35 |
|
25 | 36 | static::log($connection->app->id, static::TYPE_CONNECTION, [ |
26 | | - 'details' => "Origin: {$request->getUri()->getScheme()}://{$request->getUri()->getHost()}", |
27 | | - 'socketId' => $connection->socketId, |
| 37 | + 'details' => [ |
| 38 | + 'origin' => "{$request->getUri()->getScheme()}://{$request->getUri()->getHost()}", |
| 39 | + 'socketId' => $connection->socketId, |
| 40 | + ], |
28 | 41 | ]); |
29 | 42 | } |
30 | 43 |
|
31 | 44 | public static function occupied(ConnectionInterface $connection, string $channelName) |
32 | 45 | { |
33 | 46 | static::log($connection->app->id, static::TYPE_OCCUPIED, [ |
34 | | - 'details' => "Channel: {$channelName}", |
| 47 | + 'details' => [ |
| 48 | + 'channel' => $channelName, |
| 49 | + ], |
35 | 50 | ]); |
36 | 51 | } |
37 | 52 |
|
38 | 53 | public static function subscribed(ConnectionInterface $connection, string $channelName) |
39 | 54 | { |
40 | 55 | static::log($connection->app->id, static::TYPE_SUBSCRIBED, [ |
41 | | - 'socketId' => $connection->socketId, |
42 | | - 'details' => "Channel: {$channelName}", |
| 56 | + 'details' => [ |
| 57 | + 'socketId' => $connection->socketId, |
| 58 | + 'channel' => $channelName, |
| 59 | + ], |
43 | 60 | ]); |
44 | 61 | } |
45 | 62 |
|
46 | 63 | public static function clientMessage(ConnectionInterface $connection, stdClass $payload) |
47 | 64 | { |
48 | 65 | static::log($connection->app->id, static::TYPE_CLIENT_MESSAGE, [ |
49 | | - 'details' => "Channel: {$payload->channel}, Event: {$payload->event}", |
50 | | - 'socketId' => $connection->socketId, |
51 | | - 'data' => json_encode($payload), |
| 66 | + 'details' => [ |
| 67 | + 'socketId' => $connection->socketId, |
| 68 | + 'channel' => $payload->channel, |
| 69 | + 'event' => $payload->event, |
| 70 | + 'data' => $payload, |
| 71 | + ], |
52 | 72 | ]); |
53 | 73 | } |
54 | 74 |
|
55 | 75 | public static function disconnection(ConnectionInterface $connection) |
56 | 76 | { |
57 | 77 | static::log($connection->app->id, static::TYPE_DISCONNECTION, [ |
58 | | - 'socketId' => $connection->socketId, |
| 78 | + 'details' => [ |
| 79 | + 'socketId' => $connection->socketId, |
| 80 | + ], |
59 | 81 | ]); |
60 | 82 | } |
61 | 83 |
|
62 | 84 | public static function vacated(ConnectionInterface $connection, string $channelName) |
63 | 85 | { |
64 | 86 | static::log($connection->app->id, static::TYPE_VACATED, [ |
65 | | - 'details' => "Channel: {$channelName}", |
| 87 | + 'details' => [ |
| 88 | + 'socketId' => $connection->socketId, |
| 89 | + 'channel' => $channelName, |
| 90 | + ], |
66 | 91 | ]); |
67 | 92 | } |
68 | 93 |
|
69 | 94 | public static function apiMessage($appId, string $channel, string $event, string $payload) |
70 | 95 | { |
71 | 96 | static::log($appId, static::TYPE_API_MESSAGE, [ |
72 | | - 'details' => "Channel: {$channel}, Event: {$event}", |
73 | | - 'data' => $payload, |
| 97 | + 'details' => [ |
| 98 | + 'channel' => $connection, |
| 99 | + 'event' => $event, |
| 100 | + 'payload' => $payload, |
| 101 | + ], |
| 102 | + ]); |
| 103 | + } |
| 104 | + |
| 105 | + public static function replicatorSubscribed(string $appId, string $channel, string $serverId) |
| 106 | + { |
| 107 | + static::log($appId, static::TYPE_REPLICATOR_SUBSCRIBED, [ |
| 108 | + 'details' => [ |
| 109 | + 'serverId' => $serverId, |
| 110 | + 'channel' => $channel, |
| 111 | + ], |
| 112 | + ]); |
| 113 | + } |
| 114 | + |
| 115 | + public static function replicatorUnsubscribed(string $appId, string $channel, string $serverId) |
| 116 | + { |
| 117 | + static::log($appId, static::TYPE_REPLICATOR_UNSUBSCRIBED, [ |
| 118 | + 'details' => [ |
| 119 | + 'serverId' => $serverId, |
| 120 | + 'channel' => $channel, |
| 121 | + ], |
74 | 122 | ]); |
75 | 123 | } |
76 | 124 |
|
|
0 commit comments