Completed
Push — master ( 7571fa...8f9bf0 )
by Marc
03:08
created

SimpleFile::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
/*
3
 * This file is part of the phpflo/flowtrace package.
4
 *
5
 * (c) Marc Aschmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace PhpFlo\Logger;
12
13
use Psr\Log\AbstractLogger;
14
use Psr\Log\LoggerInterface;
15
16
/**
17
 * Class SimpleFile
18
 *
19
 * @package PhpFlo\Logger
20
 * @author Marc Aschmann <[email protected]>
21
 */
22
class SimpleFile extends AbstractLogger implements LoggerInterface
23
{
24
    const DEFAULT_FILENAME = 'flow.log';
25
26
    /**
27
     * @var string
28
     */
29
    private $logFile;
30
31
    /**
32
     * @param string $logFile path/filename to log to.
33
     */
34 1
    public function __construct($logFile)
35
    {
36 1
        $log = pathinfo($logFile);
37
38 1
        if (isset($log['dirname']) && !is_dir($log['dirname'])) {
39
            throw new \InvalidArgumentException(
40
                "Directory does not exist: {$log['dirname']}"
41
            );
42
        }
43
44 1
        if (!isset($log['filename'])) {
45
            $log['filename'] = self::DEFAULT_FILENAME;
46
        }
47 1
        $this->logFile = $logFile;
48 1
    }
49
50
    /**
51
     * Logs with an arbitrary level.
52
     *
53
     * @param mixed $level
54
     * @param string $message
55
     * @param array $context
56
     *
57
     * @return void
58
     */
59 1
    public function log($level, $message, array $context = array())
60
    {
61 1
        file_put_contents(
62 1
            $this->logFile, $message . PHP_EOL, FILE_APPEND
63 1
        );
64 1
    }
65
}
66