MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mlog.class
Ir para a documentação deste ficheiro.
1
<?php
9
class
MLog
extends
MService
10
{
14
private
$errlog;
15
19
private
$sqllog;
20
24
private
$home;
25
29
private
$isLogging;
30
34
private
$level;
35
39
private
$handler;
40
44
private
$port;
45
49
private
$socket;
50
54
private
$host;
55
var
$content
;
56
57
61
private
$logSQL = array();
62
70
function
__construct
()
71
{
72
parent::__construct();
73
$this->home = $this->manager->getConf(
'home.logs'
);
74
$this->level = $this->manager->getConf(
'logs.level'
);
75
$this->handler = $this->manager->getConf(
'logs.handler'
);
76
$this->port = $this->manager->getConf(
'logs.port'
);
77
$this->host = $this->manager->getConf(
'logs.peer'
);
78
if
(empty($this->host))
79
{
80
$this->host = $_SERVER[
'REMOTE_ADDR'
];
81
}
82
}
83
93
function
SetLog
($logname)
94
{
95
$this->manager->Assert($logname,
'MIOLO::SetLog:'
. _M(
'Empty database configuration name!'
));
96
$this->errlog = $this->home .
"/$logname-error.log"
;
97
$this->sqllog = $this->home .
"/$logname-sql.log"
;
98
}
99
111
function
LogSQL
($sql,$force=
false
,$conf=
'?'
)
112
{
113
if
($this->level < 2 )
return
;
114
115
$sqlInitial = $sql;
116
117
// junta multiplas linhas em uma so
118
$sql = preg_replace(
"/\n+ */"
,
" "
,$sql);
119
$sql = preg_replace(
"/ +/"
,
" "
,$sql);
120
121
// elimina espa?os iniciais e no final da instru??o SQL
122
$sql = trim($sql);
123
124
// traduz aspas " em ""
125
$sql = str_replace(
'"'
,
'""'
,$sql);
126
127
// data e horas no formato "dd/mes/aaaa:hh:mm:ss"
128
$dts = $this->manager->GetSysTime();
129
130
$cmd =
"/^\*\*\*|"
.
// prefixo para comandos quaisquer
131
"^ *SELECT|"
.
132
"^ *INSERT|^ *DELETE|^ *UPDATE|^ *ALTER|^ *CREATE|"
.
// comandos significantes SQL
133
"^ *BEGIN|^ *END|^ *COMMIT|^ *ROLLBACK|^ *GRANT|^ *REVOKE/i"
;
134
135
$conf = sprintf(
"%-15s"
,$conf);
136
$ip = sprintf(
"%15s"
,$this->host);
137
$uid =
''
;
138
if
( isset($this->manager->login->id) )
139
{
140
$uid = sprintf(
"%-10s"
,$this->manager->login->id);
141
}
142
143
$line =
"$ip - [$dts] - $conf - $uid \"$sql\""
;
144
145
// Fix bug "-sql.log" file on log directory
146
if
( strlen(trim($conf)) <= 0 )
147
{
148
$conf =
'undefined'
;
149
}
150
151
if
( $force || preg_match($cmd,$sql) )
152
{
153
// in case this works, make $this->sqllog obsolete
154
// error_log($line."\n",3,$this->sqllog);
155
$logfile = $this->home .
'/'
. trim($conf) .
'-sql.log'
;
156
157
error_log($line.
"\n"
,3,$logfile);
158
}
159
160
$this->
addLogSQL
($sqlInitial);
161
162
$this->
LogMessage
(
'[SQL]'
.$line);
163
}
164
165
public
function
getLogSQL
()
166
{
167
return
$this->logSQL;
168
}
169
170
public
function
setLogSQL
($logSQL)
171
{
172
$this->logSQL = $logSQL;
173
}
174
175
public
function
addLogSQL
($logSQL)
176
{
177
$this->logSQL[] = $logSQL;
178
}
179
190
function
LogError
($error,$conf=
'miolo'
)
191
{
192
if
($this->level == 0)
return
;
193
194
$ip = sprintf(
"%15s"
,$this->host);
195
$uid = sprintf(
"%-10s"
,$this->manager->auth->iduser);
196
197
// data e horas no formato "dd/mes/aaaa:hh:mm:ss"
198
$dts = $this->manager->GetSysTime();
199
200
$line =
"$ip - $uid - [$dts] \"$error\""
;
201
202
// in case this works, make $this->errlog obsolete
203
// error_log($line."\n",3,$this->errlog);
204
$logfile = $this->home .
'/'
. $conf .
'-error.log'
;
205
206
error_log($line.
"\n"
,3,$logfile);
207
208
$this->
LogMessage
(
'[ERROR]'
.$line);
209
}
210
218
function
IsLogging
()
219
{
220
return
($this->level > 0);
221
}
222
232
function
LogMessage
($msg)
233
{
234
if
( $this->
IsLogging
() )
235
{
236
$handler =
"Handler"
. $this->handler;
237
$this->{$handler}($msg);
238
}
239
}
240
250
private
function
HandlerSocket($msg)
251
{
252
if
( $this->port )
253
{
254
if
( ! $this->socket )
255
{
256
$this->socket = fsockopen($this->host, $this->port);
257
258
if
( ! $this->socket )
259
{
260
$this->trace_socket = -1;
261
}
262
}
263
fputs($this->socket, $msg.
"\n"
);
264
}
265
}
266
276
private
function
HandlerFile($msg)
277
{
278
$logfile = $this->home .
'/'
. trim($this->host) .
'.log'
;
279
$ts = $this->manager->GetSysTime();
280
error_log($ts .
': '
. $msg.
"\n"
,3,$logfile);
281
}
282
292
private
function
HandlerDb($msg)
293
{
294
$level = $this->level;
295
$this->level = 0;
296
$isLogging = $this->isLogging;
297
$this->isLogging =
false
;
298
$ts = $this->manager->GetSysTime();
299
$db = $this->manager->GetDatabase(
'miolo'
);
300
$idLog = $db->GetNewId(
'seq_miolo_log'
,
'miolo_sequence'
);
301
$sql =
new
sql
(
'idlog, timestamp, msg, host'
,
'miolo_log'
);
302
$db->Execute($sql->Insert(array($idLog,$ts,$msg,$this->host)));
303
$this->isLogging = $isLogging;
304
$this->level = $level;
305
}
306
316
private
function
HandlerScreen($msg)
317
{
318
$this->content .=
"document.addDebugInformation('"
.str_replace(
"\n"
,
''
,addslashes(nl2br($msg.
"\n"
))).
"');"
;
319
}
320
321
}
322
?>
MLog
Definição
mlog.class:10
MLog\IsLogging
IsLogging()
Definição
mlog.class:218
MLog\__construct
__construct()
Definição
mlog.class:70
MLog\addLogSQL
addLogSQL($logSQL)
Definição
mlog.class:175
MLog\LogError
LogError($error, $conf='miolo')
Definição
mlog.class:190
MLog\$content
$content
Definição
mlog.class:55
MLog\LogSQL
LogSQL($sql, $force=false, $conf='?')
Definição
mlog.class:111
MLog\LogMessage
LogMessage($msg)
Definição
mlog.class:232
MLog\setLogSQL
setLogSQL($logSQL)
Definição
mlog.class:170
MLog\getLogSQL
getLogSQL()
Definição
mlog.class:165
MLog\SetLog
SetLog($logname)
Definição
mlog.class:93
MService
Definição
mservice.class:7
sql
Definição
compatibility.class:18
classes
services
mlog.class
Gerado por
1.10.0