File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 44
55use Hypernode \DeployConfiguration \Command \Command ;
66use Hypernode \DeployConfiguration \Command \DeployCommand ;
7+ use Hypernode \DeployConfiguration \Logging \SimpleLogger ;
78use Psr \Log \LoggerInterface ;
9+ use Psr \Log \LogLevel ;
810
911class Configuration
1012{
@@ -147,6 +149,7 @@ class Configuration
147149 public function __construct (string $ gitRepository )
148150 {
149151 $ this ->gitRepository = $ gitRepository ;
152+ $ this ->logger = new SimpleLogger (LogLevel::INFO );
150153 }
151154
152155 public function getGitRepository (): string
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Hypernode \DeployConfiguration \Logging ;
4+
5+ use Psr \Log \AbstractLogger ;
6+ use Psr \Log \LogLevel ;
7+
8+ /**
9+ * Simple logger implementation using printf
10+ */
11+ class SimpleLogger extends AbstractLogger
12+ {
13+ private const LEVEL_MAPPING = [
14+ LogLevel::DEBUG => 0 ,
15+ LogLevel::INFO => 1 ,
16+ LogLevel::NOTICE => 2 ,
17+ LogLevel::WARNING => 3 ,
18+ LogLevel::ERROR => 4 ,
19+ LogLevel::CRITICAL => 5 ,
20+ LogLevel::ALERT => 6 ,
21+ LogLevel::EMERGENCY => 7
22+ ];
23+
24+ /**
25+ * @var int
26+ */
27+ private $ mappedLevel ;
28+
29+ public function __construct (string $ level )
30+ {
31+ $ this ->mappedLevel = self ::LEVEL_MAPPING [$ level ] ?? 1 ;
32+ }
33+
34+ /**
35+ * @param mixed $level
36+ * @param string|\Stringable $message
37+ * @param mixed[] $context
38+ * @return void
39+ */
40+ public function log ($ level , $ message , array $ context = array ())
41+ {
42+ if ($ this ->mapLevelToNumber ($ level ) ?? 1 >= $ this ->mappedLevel ) {
43+ printf ("%s (%s) \n" , $ message , json_encode ($ context ));
44+ }
45+ }
46+
47+ private static function mapLevelToNumber (string $ level ): int
48+ {
49+ return self ::LEVEL_MAPPING [$ level ] ?? 1 ;
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments