-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLoggerWithDateDecorator.php
More file actions
41 lines (35 loc) · 911 Bytes
/
LoggerWithDateDecorator.php
File metadata and controls
41 lines (35 loc) · 911 Bytes
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
<?php
namespace DesignPatterns\Structural\Decorator;
/**
* Decorator what adds a current date/time to logged message.
*
* It corresponds to `ConcreteDecorator` in the Decorator pattern.
*
* @author Vlad Riabchenko <contact@vria.eu>
*/
class LoggerWithDateDecorator extends LoggerDecorator
{
/**
* @var string
*/
private $format;
/**
* @param LoggerInterface $logger
* @param string $format
*/
public function __construct(LoggerInterface $logger, $format)
{
parent::__construct($logger);
$this->format = $format;
}
/**
* @inheritdoc
*/
public function log($message)
{
// Output a current date/time before logging the message.
echo date($this->format) . ": ";
// Forward log request to the wrapped logger. Note that it can also be a decorated logger.
parent::log($message);
}
}