-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathScreen.php
67 lines (57 loc) · 1.36 KB
/
Screen.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Rubix\ML\Loggers;
use function trim;
use function date;
use function strtoupper;
/**
* Screen
*
* A logger that displays log messages to the standard output.
*
* @category Machine Learning
* @package Rubix/ML
* @author Andrew DalPino
*/
class Screen extends Logger
{
/**
* The channel name that appears on each line.
*
* @var string
*/
protected string $channel;
/**
* The format of the timestamp.
*
* @var string
*/
protected string $timestampFormat;
/**
* @param string $channel
* @param string $timestampFormat
*/
public function __construct(string $channel = '', string $timestampFormat = 'Y-m-d H:i:s')
{
$this->channel = trim($channel);
$this->timestampFormat = $timestampFormat;
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param mixed[] $context
*/
public function log($level, $message, array $context = []) : void
{
$prefix = '';
if ($this->timestampFormat) {
$prefix .= '[' . date($this->timestampFormat) . '] ';
}
if ($this->channel) {
$prefix .= $this->channel . '.';
}
$prefix .= strtoupper((string) $level);
echo $prefix . ': ' . trim($message) . PHP_EOL;
}
}