/
Log.php
53 lines (35 loc) · 1.54 KB
/
Log.php
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
<?php
/*
Copyright (c) 2009 Robert Johnston
This file is part of Backbox.
Backbox is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Backbox is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Backbox. If not, see http://www.gnu.org/licenses/.
*/
class Bbx_Log {
public static function write($str, $type = 'info', $log = 'main_log') {
if (!Zend_Registry::isRegistered($log)) {
$logFilePath = APPLICATION_PATH . '/../logs/' . $log;
if(!file_exists($logFilePath)) {
touch($logFilePath);
}
else if (filesize($logFilePath) > 100000000) {
exec('tail -n 50000 ' . $logFilePath . ' > ' . $logFilePath . '__new');
copy($logFilePath . '__new', $logFilePath);
unlink($logFilePath . '__new');
}
$writer = new Zend_Log_Writer_Stream($logFilePath);
$logger = new Zend_Log($writer);
Zend_Registry::set($log,$logger);
}
$logger = Zend_Registry::get($log);
if (method_exists($logger,$type)) {
return $logger->$type($str);
}
return $logger->info($str);
}
public static function debug($str, $type = 'info', $log = 'main_log') {
return Bbx_Log::write('DEBUG: ' . $str, $type, $log);
}
}
?>