1: <?php
2: namespace Worldline\Connect\Sdk\Logging;
3:
4: use Exception;
5: use SplFileObject;
6:
7: /**
8: * Class SplFileObjectLogger
9: *
10: * @package Worldline\Connect\Sdk\Logging
11: */
12: class SplFileObjectLogger implements CommunicatorLogger
13: {
14: /** */
15: const DATE_FORMAT_STRING = DATE_ATOM;
16:
17: /** @var SplFileObject */
18: private $splFileObject;
19:
20: /** @param SplFileObject $splFileObject */
21: public function __construct(SplFileObject $splFileObject)
22: {
23: $this->splFileObject = $splFileObject;
24: }
25:
26: /** @return SplFileObject */
27: public function getSplFileObject()
28: {
29: return $this->splFileObject;
30: }
31:
32: /** @inheritdoc */
33: public function log($message)
34: {
35: $this->splFileObject->fwrite($this->getDatePrefix() . $message . PHP_EOL);
36: }
37:
38: /** @inheritdoc */
39: public function logException($message, Exception $exception)
40: {
41: $this->splFileObject->fwrite($this->getDatePrefix() . $message . PHP_EOL . $exception . PHP_EOL);
42: }
43:
44: /** @return string */
45: protected function getDatePrefix()
46: {
47: return date(static::DATE_FORMAT_STRING) . ' ';
48: }
49: }
50: