1: | <?php |
2: | namespace Worldline\Connect\Sdk\Logging; |
3: | |
4: | use Exception; |
5: | use UnexpectedValueException; |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | class ResourceLogger implements CommunicatorLogger |
13: | { |
14: | |
15: | const DATE_FORMAT_STRING = DATE_ATOM; |
16: | |
17: | |
18: | protected $resource; |
19: | |
20: | |
21: | public function __construct($resource) |
22: | { |
23: | if (!is_resource($resource)) { |
24: | throw new UnexpectedValueException('resource expected'); |
25: | } |
26: | $this->resource = $resource; |
27: | } |
28: | |
29: | |
30: | public function log($message) |
31: | { |
32: | fwrite($this->resource, $this->getDatePrefix() . $message . PHP_EOL); |
33: | } |
34: | |
35: | |
36: | public function logException($message, Exception $exception) |
37: | { |
38: | fwrite($this->resource, $this->getDatePrefix() . $message . PHP_EOL . $exception . PHP_EOL); |
39: | } |
40: | |
41: | |
42: | protected function getDatePrefix() |
43: | { |
44: | return date(static::DATE_FORMAT_STRING) . ' '; |
45: | } |
46: | } |
47: | |