-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlogs-stream.php
29 lines (20 loc) · 996 Bytes
/
logs-stream.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
// this example shows how the containerLogsStream() call can be used to get the logs of the given container.
// demonstrates the streaming logs API, which can be used to dump the logs as they arrive
require __DIR__ . '/../vendor/autoload.php';
$container = isset($argv[1]) ? $argv[1] : 'asd';
echo 'Dumping logs (last 100 lines) of container "' . $container . '" (pass as argument to this example)' . PHP_EOL;
$client = new Clue\React\Docker\Client();
// use caret notation for any control characters except \t, \r and \n
$caret = new Clue\CaretNotation\Encoder("\t\r\n");
$stream = $client->containerLogsStream($container, true, true, true, 0, false, 100);
$stream->on('data', function ($data) use ($caret) {
echo $caret->encode($data);
});
$stream->on('error', function (Exception $e) {
// will be called if either parameter is invalid
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
$stream->on('close', function ($e = null) {
echo 'CLOSED' . PHP_EOL . $e;
});