JsonFormatter::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php
2
3
/**
4
 * AppserverIo\Logger\Handlers\JsonFormatter
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      http://github.com/appserver-io/logger
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Logger\Formatters;
22
23
/**
24
 * A formatter that encodes the formatted message with PHP json_encode() method.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2015 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      http://github.com/appserver-io/logger
30
 * @link      http://www.appserver.io
31
 * @see       http://php.net/manual/en/function.sprintf.php
32
 */
33
class JsonFormatter extends StandardFormatter
34
{
35
36
    /**
37
     * Initializes the handler instance with channel name and log level.
38
     *
39
     * @param string|null $messageFormat The message format, MUST be valid for sprintf
40
     * @param string|null $dateFormat    The date format, valid for PHP date() function
41
     */
42
    public function __construct($messageFormat = null, $dateFormat = null)
43
    {
44
45
        // initialize message and date format
46
        if ($messageFormat == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $messageFormat of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
47
            $messageFormat = '{ "timestamp": "%s", "id": "%s", "level" : "%s", "message": "%s", "context": %s }';
48
        }
49
50
        // pass variables to parent
51
        parent::__construct($messageFormat, $dateFormat);
52
    }
53
}
54