@@ -12,5 +12,5 @@ |
||
12 | 12 | */ |
13 | 13 | interface FormatterInterface |
14 | 14 | { |
15 | - public function format(Record $record); |
|
15 | + public function format(Record $record); |
|
16 | 16 | } |
@@ -13,45 +13,45 @@ |
||
13 | 13 | */ |
14 | 14 | class StandardFormatter implements FormatterInterface |
15 | 15 | { |
16 | - const FORMAT = "[%datetime%] %level%: %message%\n%contextPlaceholder%"; |
|
17 | - const CONTEXT_FORMAT = "Context:\n%context%\n"; |
|
18 | - const DATETIME_FORMAT = 'Y-m-d H:i:s.u'; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var DumperInterface |
|
22 | - */ |
|
23 | - protected $dumper; |
|
24 | - |
|
25 | - public function __construct(DumperInterface $dumper) |
|
26 | - { |
|
27 | - $this->dumper = $dumper; |
|
28 | - } |
|
29 | - |
|
30 | - public function format(Record $record) |
|
31 | - { |
|
32 | - $contextString = ''; |
|
33 | - |
|
34 | - if ($context = $record->getContext()) { |
|
35 | - $contextString = strtr( |
|
36 | - self::CONTEXT_FORMAT, |
|
37 | - [ |
|
38 | - '%context%' => $this->dumper->dump($context), |
|
39 | - ] |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - $string = strtr( |
|
44 | - self::FORMAT, |
|
45 | - [ |
|
46 | - '%datetime%' => $record->getDatetime()->format( |
|
47 | - static::DATETIME_FORMAT |
|
48 | - ), |
|
49 | - '%level%' => $record->getLevel(), |
|
50 | - '%message%' => $record->getMessage(), |
|
51 | - '%contextPlaceholder%' => $contextString, |
|
52 | - ] |
|
53 | - ); |
|
54 | - |
|
55 | - return $string; |
|
56 | - } |
|
16 | + const FORMAT = "[%datetime%] %level%: %message%\n%contextPlaceholder%"; |
|
17 | + const CONTEXT_FORMAT = "Context:\n%context%\n"; |
|
18 | + const DATETIME_FORMAT = 'Y-m-d H:i:s.u'; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var DumperInterface |
|
22 | + */ |
|
23 | + protected $dumper; |
|
24 | + |
|
25 | + public function __construct(DumperInterface $dumper) |
|
26 | + { |
|
27 | + $this->dumper = $dumper; |
|
28 | + } |
|
29 | + |
|
30 | + public function format(Record $record) |
|
31 | + { |
|
32 | + $contextString = ''; |
|
33 | + |
|
34 | + if ($context = $record->getContext()) { |
|
35 | + $contextString = strtr( |
|
36 | + self::CONTEXT_FORMAT, |
|
37 | + [ |
|
38 | + '%context%' => $this->dumper->dump($context), |
|
39 | + ] |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + $string = strtr( |
|
44 | + self::FORMAT, |
|
45 | + [ |
|
46 | + '%datetime%' => $record->getDatetime()->format( |
|
47 | + static::DATETIME_FORMAT |
|
48 | + ), |
|
49 | + '%level%' => $record->getLevel(), |
|
50 | + '%message%' => $record->getMessage(), |
|
51 | + '%contextPlaceholder%' => $contextString, |
|
52 | + ] |
|
53 | + ); |
|
54 | + |
|
55 | + return $string; |
|
56 | + } |
|
57 | 57 | } |
@@ -10,9 +10,9 @@ |
||
10 | 10 | */ |
11 | 11 | interface LoggerInterface extends \Psr\Log\LoggerInterface |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $name |
|
15 | - * @return Workflow |
|
16 | - */ |
|
17 | - public function workflow($name); |
|
13 | + /** |
|
14 | + * @param string $name |
|
15 | + * @return Workflow |
|
16 | + */ |
|
17 | + public function workflow($name); |
|
18 | 18 | } |
@@ -10,75 +10,75 @@ |
||
10 | 10 | */ |
11 | 11 | class Record |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $context; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $context; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @var \DateTime |
|
20 | - */ |
|
21 | - protected $datetime; |
|
18 | + /** |
|
19 | + * @var \DateTime |
|
20 | + */ |
|
21 | + protected $datetime; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $level; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $level; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $message; |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $message; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Record constructor. |
|
35 | - * |
|
36 | - * @param \DateTime $datetime |
|
37 | - * @param string $message |
|
38 | - * @param string $level |
|
39 | - * @param array $context |
|
40 | - */ |
|
41 | - public function __construct( |
|
42 | - \DateTime $datetime, |
|
43 | - $message, |
|
44 | - $level, |
|
45 | - array $context |
|
46 | - ) { |
|
47 | - $this->datetime = $datetime; |
|
48 | - $this->message = (string)$message; |
|
49 | - $this->level = (string)$level; |
|
50 | - $this->context = $context; |
|
51 | - } |
|
33 | + /** |
|
34 | + * Record constructor. |
|
35 | + * |
|
36 | + * @param \DateTime $datetime |
|
37 | + * @param string $message |
|
38 | + * @param string $level |
|
39 | + * @param array $context |
|
40 | + */ |
|
41 | + public function __construct( |
|
42 | + \DateTime $datetime, |
|
43 | + $message, |
|
44 | + $level, |
|
45 | + array $context |
|
46 | + ) { |
|
47 | + $this->datetime = $datetime; |
|
48 | + $this->message = (string)$message; |
|
49 | + $this->level = (string)$level; |
|
50 | + $this->context = $context; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return \DateTime |
|
55 | - */ |
|
56 | - public function getDatetime() |
|
57 | - { |
|
58 | - return $this->datetime; |
|
59 | - } |
|
53 | + /** |
|
54 | + * @return \DateTime |
|
55 | + */ |
|
56 | + public function getDatetime() |
|
57 | + { |
|
58 | + return $this->datetime; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function getMessage() |
|
65 | - { |
|
66 | - return $this->message; |
|
67 | - } |
|
61 | + /** |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function getMessage() |
|
65 | + { |
|
66 | + return $this->message; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function getLevel() |
|
73 | - { |
|
74 | - return $this->level; |
|
75 | - } |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function getLevel() |
|
73 | + { |
|
74 | + return $this->level; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - public function getContext() |
|
81 | - { |
|
82 | - return $this->context; |
|
83 | - } |
|
77 | + /** |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + public function getContext() |
|
81 | + { |
|
82 | + return $this->context; |
|
83 | + } |
|
84 | 84 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | */ |
11 | 11 | interface DumperInterface |
12 | 12 | { |
13 | - public function dump(array $context); |
|
13 | + public function dump(array $context); |
|
14 | 14 | } |
@@ -13,24 +13,24 @@ |
||
13 | 13 | */ |
14 | 14 | class SymfonyVarDumper implements DumperInterface |
15 | 15 | { |
16 | - /** |
|
17 | - * @var VarCloner |
|
18 | - */ |
|
19 | - protected $cloner; |
|
16 | + /** |
|
17 | + * @var VarCloner |
|
18 | + */ |
|
19 | + protected $cloner; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var CliDumper |
|
23 | - */ |
|
24 | - protected $dumper; |
|
21 | + /** |
|
22 | + * @var CliDumper |
|
23 | + */ |
|
24 | + protected $dumper; |
|
25 | 25 | |
26 | - public function __construct($flags = CliDumper::DUMP_LIGHT_ARRAY) |
|
27 | - { |
|
28 | - $this->cloner = new VarCloner(); |
|
29 | - $this->dumper = new CliDumper(null, null, $flags); |
|
30 | - } |
|
26 | + public function __construct($flags = CliDumper::DUMP_LIGHT_ARRAY) |
|
27 | + { |
|
28 | + $this->cloner = new VarCloner(); |
|
29 | + $this->dumper = new CliDumper(null, null, $flags); |
|
30 | + } |
|
31 | 31 | |
32 | - public function dump(array $context) |
|
33 | - { |
|
34 | - return $this->dumper->dump($this->cloner->cloneVar($context), true); |
|
35 | - } |
|
32 | + public function dump(array $context) |
|
33 | + { |
|
34 | + return $this->dumper->dump($this->cloner->cloneVar($context), true); |
|
35 | + } |
|
36 | 36 | } |
@@ -10,8 +10,8 @@ |
||
10 | 10 | */ |
11 | 11 | class PrintRDumper implements DumperInterface |
12 | 12 | { |
13 | - public function dump(array $context) |
|
14 | - { |
|
15 | - return print_r($context, true); |
|
16 | - } |
|
13 | + public function dump(array $context) |
|
14 | + { |
|
15 | + return print_r($context, true); |
|
16 | + } |
|
17 | 17 | } |
@@ -12,19 +12,19 @@ |
||
12 | 12 | */ |
13 | 13 | class TracyDumper implements DumperInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $options; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $options; |
|
19 | 19 | |
20 | - public function __construct( |
|
21 | - array $options = [Dumper::DEPTH => 8, Dumper::TRUNCATE => 512] |
|
22 | - ) { |
|
23 | - $this->options = $options; |
|
24 | - } |
|
20 | + public function __construct( |
|
21 | + array $options = [Dumper::DEPTH => 8, Dumper::TRUNCATE => 512] |
|
22 | + ) { |
|
23 | + $this->options = $options; |
|
24 | + } |
|
25 | 25 | |
26 | - public function dump(array $context) |
|
27 | - { |
|
28 | - return Dumper::toText($context, $this->options); |
|
29 | - } |
|
26 | + public function dump(array $context) |
|
27 | + { |
|
28 | + return Dumper::toText($context, $this->options); |
|
29 | + } |
|
30 | 30 | } |
@@ -12,70 +12,70 @@ |
||
12 | 12 | */ |
13 | 13 | class Logger extends \Monolog\Logger implements LoggerInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * Detailed workflow debug information |
|
17 | - */ |
|
18 | - const WORKFLOW = 111; |
|
15 | + /** |
|
16 | + * Detailed workflow debug information |
|
17 | + */ |
|
18 | + const WORKFLOW = 111; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var FormatterInterface |
|
22 | - */ |
|
23 | - protected $workflowFormatter; |
|
20 | + /** |
|
21 | + * @var FormatterInterface |
|
22 | + */ |
|
23 | + protected $workflowFormatter; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Logging levels from syslog protocol defined in RFC 5424 |
|
27 | - * |
|
28 | - * @var array $levels Logging levels |
|
29 | - */ |
|
30 | - protected static $levels = [ |
|
31 | - self::WORKFLOW => 'WORKFLOW', |
|
32 | - ]; |
|
25 | + /** |
|
26 | + * Logging levels from syslog protocol defined in RFC 5424 |
|
27 | + * |
|
28 | + * @var array $levels Logging levels |
|
29 | + */ |
|
30 | + protected static $levels = [ |
|
31 | + self::WORKFLOW => 'WORKFLOW', |
|
32 | + ]; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Logger constructor. |
|
36 | - * |
|
37 | - * @param string $name |
|
38 | - * @param FormatterInterface $formatter |
|
39 | - * @param array $handlers |
|
40 | - * @param array $processors |
|
41 | - */ |
|
42 | - public function __construct( |
|
43 | - $name, |
|
44 | - FormatterInterface $formatter, |
|
45 | - $handlers = [], |
|
46 | - $processors = [] |
|
47 | - ) { |
|
48 | - parent::__construct($name, $handlers, $processors); |
|
49 | - self::$levels += parent::$levels; |
|
50 | - $this->workflowFormatter = $formatter; |
|
51 | - } |
|
34 | + /** |
|
35 | + * Logger constructor. |
|
36 | + * |
|
37 | + * @param string $name |
|
38 | + * @param FormatterInterface $formatter |
|
39 | + * @param array $handlers |
|
40 | + * @param array $processors |
|
41 | + */ |
|
42 | + public function __construct( |
|
43 | + $name, |
|
44 | + FormatterInterface $formatter, |
|
45 | + $handlers = [], |
|
46 | + $processors = [] |
|
47 | + ) { |
|
48 | + parent::__construct($name, $handlers, $processors); |
|
49 | + self::$levels += parent::$levels; |
|
50 | + $this->workflowFormatter = $formatter; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return \DateTimeZone |
|
55 | - */ |
|
56 | - protected function timezoneFactory() |
|
57 | - { |
|
58 | - if (static::$timezone) { |
|
59 | - return static::$timezone; |
|
60 | - } |
|
53 | + /** |
|
54 | + * @return \DateTimeZone |
|
55 | + */ |
|
56 | + protected function timezoneFactory() |
|
57 | + { |
|
58 | + if (static::$timezone) { |
|
59 | + return static::$timezone; |
|
60 | + } |
|
61 | 61 | |
62 | - $timezone = date_default_timezone_get() ?: 'UTC'; |
|
62 | + $timezone = date_default_timezone_get() ?: 'UTC'; |
|
63 | 63 | |
64 | - return static::$timezone = new \DateTimeZone($timezone); |
|
65 | - } |
|
64 | + return static::$timezone = new \DateTimeZone($timezone); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param string $name |
|
69 | - * @return Workflow |
|
70 | - */ |
|
71 | - public function workflow($name) |
|
72 | - { |
|
73 | - return new Workflow( |
|
74 | - $this, |
|
75 | - $this->workflowFormatter, |
|
76 | - $this->timezoneFactory(), |
|
77 | - $name, |
|
78 | - static::WORKFLOW |
|
79 | - ); |
|
80 | - } |
|
67 | + /** |
|
68 | + * @param string $name |
|
69 | + * @return Workflow |
|
70 | + */ |
|
71 | + public function workflow($name) |
|
72 | + { |
|
73 | + return new Workflow( |
|
74 | + $this, |
|
75 | + $this->workflowFormatter, |
|
76 | + $this->timezoneFactory(), |
|
77 | + $name, |
|
78 | + static::WORKFLOW |
|
79 | + ); |
|
80 | + } |
|
81 | 81 | } |