forked from netcommons/NetCommons2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger_SimpleFile.class.php
More file actions
154 lines (140 loc) · 4.05 KB
/
Logger_SimpleFile.class.php
File metadata and controls
154 lines (140 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Maple - PHP Web Application Framework
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @package Maple.logger
* @author TAKAHASHI Kunihiko <kunit@kunit.jp>
* @copyright 2004-2006 The Maple Project
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Logger_SimpleFile.class.php,v 1.2 2006/09/29 06:16:27 Ryuji.M Exp $
*/
/**
* 使用するログファイル名
*
* @type string
* @since 3.0.0
**/
define("LOG_FILENAME", "/maple.log");
/**
* ファイルに出力するLogger
*
* @package Maple.logger
* @author TAKAHASHI Kunihiko <kunit@kunit.jp>
* @copyright 2004-2006 The Maple Project
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @access public
* @since 3.0.0
*/
class Logger_SimpleFile extends Logger
{
/**
* コンストラクター
*
* @access private
* @since 3.0.0
*/
function Logger_SimpleFile()
{
}
/**
* fatalレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
* @since 3.0.0
*/
function fatal($message, $caller = null)
{
$this->output(LEVEL_FATAL, $message, $caller);
}
/**
* errorレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
* @since 3.0.0
*/
function error($message, $caller = null)
{
$this->output(LEVEL_ERROR, $message, $caller);
}
/**
* warnレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
* @since 3.0.0
*/
function warn($message, $caller = null)
{
$this->output(LEVEL_WARN, $message, $caller);
}
/**
* infoレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
* @since 3.0.0
*/
function info($message, $caller = null)
{
$this->output(LEVEL_INFO, $message, $caller);
}
/**
* debugレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
* @since 3.0.0
*/
function debug($message, $caller = null)
{
$this->output(LEVEL_DEBUG, $message, $caller);
}
/**
* traceレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
* @since 3.0.0
*/
function trace($message, $caller = null)
{
$this->output(LEVEL_TRACE, $message, $caller);
}
/**
* ログを出力する関数
*
* @param integer $logLevel ログレベル
* @param string $message エラーメッセージ
* @param mixed $caller 呼び出し元
* @access public
* @since 3.0.0
*/
function output($logLevel, $message, $caller)
{
if (LOG_LEVEL <= $logLevel) {
$now = date("Y/m/d H:i:s");
$levels = array(
LEVEL_FATAL => 'fatal',
LEVEL_ERROR => 'error',
LEVEL_WARN => 'warn',
LEVEL_INFO => 'info',
LEVEL_DEBUG => 'debug',
LEVEL_TRACE => 'trace',
);
$message = sprintf("[%s] [%s] %s - %s\n", $now, $levels[$logLevel], $message, $caller);
@error_log($message, 3, LOG_DIR . LOG_FILENAME);
}
}
}
?>