12 private static $FilePath = null;
13 private static $MaxFileSize = 0;
15 public static function Initialize($filePath = null, $maxFileSize = null) {
17 self::$FilePath = $filePath;
18 }
else if (defined(
'LOG_FILENAME')) {
19 self::$FilePath = LOG_FOLDER . LOG_FILENAME;
21 self::$FilePath = LOG_FOLDER .
"app.log";
23 if ($maxFileSize !== null) {
24 self::$MaxFileSize = $maxFileSize;
25 }
else if (defined(
'LOG_MAXFILESIZE')) {
26 self::$MaxFileSize = LOG_MAXFILESIZE;
30 private static function WriteToFile($text) {
31 $dir = dirname(self::$FilePath);
32 if (!file_exists($dir) && is_writable(dirname($dir))) {
36 }
catch (Exception $ex) {
40 if (file_exists($dir) && is_writable($dir)) {
41 if (self::$MaxFileSize > 0) {
42 if (@filesize(self::$FilePath) > self::$MaxFileSize) {
43 $ext = Utils::GetFilenameExtension(basename(self::$FilePath));
44 $suffix =
"_" . date(
"d-m-Y_H-i-s") . $ext;
45 $bakFile = substr(self::$FilePath, 0, strlen($ext) - 1) . $suffix;
46 @rename(self::$FilePath, $bakFile);
49 file_put_contents(self::$FilePath, $text, FILE_APPEND);
53 private static function SanatizeText($log) {
55 $text = str_replace(
"\n",
" ", $text);
56 $text = str_replace(
"\r",
" ", $text);
57 $text = str_replace(
" ",
" ", $text);
68 private static function AppendLog($prefix, $log) {
70 $text = ($AppId->IsValid() ?
"(" . $AppId->Name .
") " :
"") .
73 self::SanatizeText($log) .
75 self::WriteToFile($text);
78 public static function Info($log) {
79 self::AppendLog(
"INFO", $log);
83 self::AppendLog(
"WARNING", $log);
86 public static function Error($log) {
87 self::AppendLog(
"ERROR", $log);
static Initialize($filePath=null, $maxFileSize=null)