Failed Conditions
Pull Request — master (#321)
by Anton
23:35 queued 08:33
created

errorLog()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 11
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 16
ccs 0
cts 10
cp 0
crap 20
rs 9.9
1
<?php
2
/**
3
 * Simple functions of Application
4
 * be careful with this way
5
 */
6
7
namespace Application;
8
9
/**
10
 * Write Exception to log file
11
 *
12
 * @param \Throwable $exception
13
 *
14
 * @return void
15
 */
16
function errorLog(\Throwable $exception)
17
{
18
    if (getenv('BLUZ_LOG') && is_dir(PATH_DATA . '/logs') && is_writable(PATH_DATA . '/logs')) {
19
        // [Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /var/www/...
20
        $message = '[' . date('r') . '] [' . get_class($exception) . '] '
21
            . '[' . $_SERVER['REQUEST_URI'] . ']'
22
            . $exception->getFile() . ':' . $exception->getLine()
23
            . ': '
24
            . trim($exception->getMessage())
25
            . "\n";
26
27
        // write log
28
        file_put_contents(
29
            PATH_DATA . '/logs/' . date('Y-m-d') . '.log',
30
            $message,
31
            FILE_APPEND | LOCK_EX
32
        );
33
    }
34
}
35