Logger::LogError()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
/**
3
 *
4
 * KNUT7 K7F (https://marciozebedeu.com/)
5
 * KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/)
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE.txt
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @link      https://github.com/knut7/framework/ for the canonical source repository
12
 * @copyright (c) 2015.  KNUT7  Software Technologies AO Inc. (https://marciozebedeu.com/)
13
 * @license   https://marciozebedeu.com/license/new-bsd New BSD License
14
 * @author    Marcio Zebedeu - [email protected]
15
 * @version   1.0.7
16
 *
17
 *
18
 */
19
20
21
namespace Ballybran\Helpers\Log;
22
23
24
/**
25
 * Class Logger
26
 * @package Ballybran\Helpers\Log
27
 */
28
class Logger
29
{
30
31
    /**
32
     * @var
33
     */
34
    protected $file;
35
36
    /**
37
     * @var
38
     */
39
    protected $content;
40
41
    /**
42
     * @var int
43
     */
44
    protected $writeFlag;
45
46
    /**
47
     * @var string
48
     */
49
    protected $endRow;
50
51
    /**
52
     * @var
53
     */
54
    private $newRow;
55
56
57
    /**
58
     * Logger constructor.
59
     * @param $file
60
     * @param string $endRow
61
     * @param int $writeFlag
62
     */
63
    public function __construct($file, $endRow = "\n", $writeFlag = FILE_APPEND)
64
    {
65
66
        $this->file = DIR_LOGS . $file;
67
68
        $this->writeFlag = $writeFlag;
69
70
        $this->endRow = $endRow;
71
        $this->newRow;
72
73
    }
74
75
    /**
76
     * @param string $content
77
     * @param int $newLines
78
     * @return $this
79
     */
80
    public function AddRow($content = "", $newLines = 1)
81
    {
82
83
        for ($m = 0; $m < $newLines; $m++) {
84
            $this->newRow .= $this->endRow;
85
86
        }
87
        $this->content .= $content . $this->newRow;
88
89
        return $this;
90
91
    }
92
93
94
    /**
95
     * @return $this
96
     */
97
    public function Commit()
98
    {
99
        file_put_contents($this->file, $this->content, $this->writeFlag);
100
101
        return $this;
102
    }
103
104
    /**
105
     * @return $this
106
     */
107
    public function getCommit()
108
    {
109
        file_get_contents($this->file, $this->content);
110
111
        return $this;
112
113
    }
114
115
    /**
116
     * @param $error
117
     * @param int $newLines
118
     */
119
    public function LogError($error, $newLines = 1)
120
    {
121
        if ($error != "") {
122
123
            $this->AddRow($error, $newLines);
124
            echo $error;
125
126
        }
127
128
    }
129
130
}
131