Skip to content

Commit 532f068

Browse files
authored
Create SampleStdLogger.php
1 parent 2f8eec2 commit 532f068

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/Logger/SampleStdLogger.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace YdbPlatform\Ydb\Logger;
4+
5+
class SampleStdLogger implements \Psr\Log\LoggerInterface
6+
{
7+
const DEBUG = 7;
8+
const INFO = 6;
9+
const NOTICE = 5;
10+
const WARNING = 4;
11+
const ERROR = 3;
12+
const CRITICAL = 2;
13+
const ALERT = 1;
14+
const EMERGENCY = 0;
15+
16+
protected static $levels = [
17+
self::DEBUG => 'DEBUG',
18+
self::INFO => 'INFO',
19+
self::NOTICE => 'NOTICE',
20+
self::WARNING => 'WARNING',
21+
self::ERROR => 'ERROR',
22+
self::CRITICAL => 'CRITICAL',
23+
self::ALERT => 'ALERT',
24+
self::EMERGENCY => 'EMERGENCY',
25+
];
26+
27+
protected $level;
28+
public function __construct(int $level)
29+
{
30+
$this->level = $level;
31+
}
32+
33+
public function emergency($message, array $context = []): void
34+
{
35+
$this->log(self::EMERGENCY, $message, $context);
36+
}
37+
38+
public function alert($message, array $context = []): void
39+
{
40+
$this->log(self::EMERGENCY, $message, $context);
41+
}
42+
43+
public function critical($message, array $context = []): void
44+
{
45+
$this->log(self::EMERGENCY, $message, $context);
46+
}
47+
48+
public function error($message, array $context = []): void
49+
{
50+
$this->log(self::EMERGENCY, $message, $context);
51+
}
52+
53+
public function warning($message, array $context = []): void
54+
{
55+
$this->log(self::EMERGENCY, $message, $context);
56+
}
57+
58+
public function notice($message, array $context = []): void
59+
{
60+
$this->log(self::EMERGENCY, $message, $context);
61+
}
62+
63+
public function info($message, array $context = []): void
64+
{
65+
$this->log(self::EMERGENCY, $message, $context);
66+
}
67+
68+
public function debug($message, array $context = []): void
69+
{
70+
$this->log(self::EMERGENCY, $message, $context);
71+
}
72+
73+
public function log($level, $message, array $context = []): void
74+
{
75+
if ($level>$this->level) return;
76+
fwrite(STDERR,
77+
date("d/m/y H:i")." ".$level. " ".$message." ".json_encode($context)
78+
);
79+
}
80+
}

0 commit comments

Comments
 (0)