1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Kotori.php |
4
|
|
|
* |
5
|
|
|
* A Tiny Model-View-Controller PHP Framework |
6
|
|
|
* |
7
|
|
|
* This content is released under the Apache 2 License |
8
|
|
|
* |
9
|
|
|
* Copyright (c) 2015-2017 Kotori Technology. All rights reserved. |
10
|
|
|
* |
11
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
12
|
|
|
* you may not use this file except in compliance with the License. |
13
|
|
|
* You may obtain a copy of the License at |
14
|
|
|
* |
15
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
16
|
|
|
* |
17
|
|
|
* Unless required by applicable law or agreed to in writing, software |
18
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
19
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20
|
|
|
* See the License for the specific language governing permissions and |
21
|
|
|
* limitations under the License. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Logging Class |
26
|
|
|
* |
27
|
|
|
* @package Kotori |
28
|
|
|
* @subpackage Debug |
29
|
|
|
* @author Kokororin |
30
|
|
|
* @link https://kotori.love |
31
|
|
|
*/ |
32
|
|
|
namespace Kotori\Debug; |
33
|
|
|
|
34
|
|
|
use Kotori\Core\Container; |
35
|
|
|
use Kotori\Core\Helper; |
36
|
|
|
|
37
|
|
|
class Logger |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* Class constructor |
41
|
|
|
* |
42
|
|
|
* Initialize Logger. |
43
|
|
|
* |
44
|
|
|
* @return void |
|
|
|
|
45
|
|
|
*/ |
46
|
1 |
|
public function __construct() |
47
|
|
|
{ |
48
|
1 |
|
Hook::listen(__CLASS__); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Write Log File |
53
|
|
|
* |
54
|
|
|
* @param string $msg |
55
|
|
|
* @param string $level |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
4 |
|
public function write($msg, $level = 'APP') |
59
|
|
|
{ |
60
|
4 |
|
if (!Container::get('config')->get('app_debug') && $level != 'APP') { |
61
|
4 |
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$msg = date('[Y-m-d H:i:s]') . "\r\n" . "[{$level}]" . "\r\n" . $msg . "\r\n\r\n"; |
65
|
|
|
$logPath = Container::get('config')->get('app_full_path') . '/logs'; |
66
|
|
|
if (!file_exists($logPath)) { |
67
|
|
|
Helper::mkdirs($logPath); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (file_exists($logPath)) { |
71
|
|
|
file_put_contents($logPath . '/' . date('Ymd') . '.log', $msg, FILE_APPEND); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Write Normal Log |
77
|
|
|
* |
78
|
|
|
* @param string $msg |
79
|
|
|
*/ |
80
|
|
|
public function normal($msg) |
81
|
|
|
{ |
82
|
|
|
$this->write($msg, 'NORMAL'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Write SQL Log |
87
|
|
|
* |
88
|
|
|
* @param string $msg |
89
|
|
|
*/ |
90
|
4 |
|
public function sql($msg) |
91
|
|
|
{ |
92
|
4 |
|
$this->write($msg, 'SQL'); |
93
|
4 |
|
} |
94
|
|
|
} |
95
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.