Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezlog.php
Go to the documentation of this file.
1 <?php
20 class eZLog
21 {
22 const MAX_LOGROTATE_FILES = 3;
23 const MAX_LOGFILE_SIZE = 204800; // 200*1024
24
30 static function write( $message, $logName = 'common.log', $dir = 'var/log' )
31 {
32 $fileName = $dir . '/' . $logName;
33 $oldumask = @umask( 0 );
34
35 $fileExisted = file_exists( $fileName );
36 if ( $fileExisted and
37 filesize( $fileName ) > eZLog::maxLogSize() )
38 {
39 if ( eZLog::rotateLog( $fileName ) )
40 $fileExisted = false;
41 }
42 else if ( !$fileExisted and !file_exists( $dir ) )
43 {
44 eZDir::mkdir( $dir, false, true );
45 }
46
47 $logFile = @fopen( $fileName, "a" );
48 if ( $logFile )
49 {
50 $time = date( "M d Y H:i:s", strtotime( "now" ) );
51 $logMessage = "[ " . $time . " ] $message\n";
52 @fwrite( $logFile, $logMessage );
53 @fclose( $logFile );
54 if ( !$fileExisted )
55 {
56 $ini = eZINI::instance();
57 $permissions = octdec( $ini->variable( 'FileSettings', 'LogFilePermissions' ) );
58 @chmod( $fileName, $permissions );
59 }
60 @umask( $oldumask );
61 }
62 else
63 {
64 eZDebug::writeError( 'Couldn\'t create the log file "' . $fileName . '"', __METHOD__ );
65 }
66 }
67
72 static function writeStorageLog( $name, $dir = false )
73 {
74 $ini = eZINI::instance();
75 $varDir = $ini->variable( 'FileSettings', 'VarDir' );
76 $logDir = $ini->variable( 'FileSettings', 'LogDir' );
77 $logName = 'storage.log';
78 $fileName = $varDir . '/' . $logDir . '/' . $logName;
79 $oldumask = @umask( 0 );
80
81 clearstatcache( true, $fileName );
82 $fileExisted = file_exists( $fileName );
83 if ( $fileExisted and
84 filesize( $fileName ) > eZLog::maxLogSize() )
85 {
86 if ( eZLog::rotateLog( $fileName ) )
87 $fileExisted = false;
88 }
89 else if ( !$fileExisted and !file_exists( $varDir . '/' . $logDir ) )
90 {
91 eZDir::mkdir( $varDir . '/' . $logDir, false, true );
92 }
93
94 if ( $dir !== false )
95 {
96 $dir = preg_replace( "#/$#", "", $dir );
97 $dir .= "/";
98 }
99 else
100 {
101 $dir = "";
102 }
103
104 $logFile = @fopen( $fileName, "a" );
105 if ( $logFile )
106 {
107 $time = date( "M d Y H:i:s", strtotime( "now" ) );
108 $logMessage = "[ " . $time . " ] [" . $dir . $name . "]\n";
109 @fwrite( $logFile, $logMessage );
110 @fclose( $logFile );
111 if ( !$fileExisted )
112 {
113 $permissions = octdec( $ini->variable( 'FileSettings', 'LogFilePermissions' ) );
114 @chmod( $fileName, $permissions );
115 }
116 @umask( $oldumask );
117 }
118 else
119 {
120 eZDebug::writeError( 'Couldn\'t create the log file "' . $fileName . '"', __METHOD__ );
121 }
122 }
123
128 static function maxLogSize()
129 {
130 $maxLogSize =& $GLOBALS['eZMaxLogSize'];
131 if ( isset( $maxLogSize ) )
132 {
133 return $maxLogSize;
134 }
135 else if ( defined( 'CUSTOM_LOG_MAX_FILE_SIZE' ) )
136 {
137 self::setMaxLogSize( (int)CUSTOM_LOG_MAX_FILE_SIZE );
138 return (int)CUSTOM_LOG_MAX_FILE_SIZE;
139 }
140 return self::MAX_LOGFILE_SIZE;
141 }
142
147 static function setMaxLogSize( $size )
148 {
149 $GLOBALS['eZMaxLogSize'] = $size;
150 }
151
156 static function maxLogrotateFiles()
157 {
158 $maxLogrotateFiles =& $GLOBALS['eZMaxLogrotateFiles'];
159 if ( isset( $maxLogrotateFiles ) )
160 {
161 return $maxLogrotateFiles;
162 }
163 else if ( defined( 'CUSTOM_LOG_ROTATE_FILES' ) )
164 {
165 self::setLogrotateFiles( (int)CUSTOM_LOG_ROTATE_FILES );
166 return (int)CUSTOM_LOG_ROTATE_FILES;
167 }
168 return self::MAX_LOGROTATE_FILES;
169 }
170
178 static function rotateLog( $fileName )
179 {
180 $maxLogrotateFiles = eZLog::maxLogrotateFiles();
181 if ( $maxLogrotateFiles == 0 )
182 {
183 return;
184 }
185 for ( $i = $maxLogrotateFiles; $i > 0; --$i )
186 {
187 $logRotateName = $fileName . '.' . $i;
188 if ( file_exists( $logRotateName ) )
189 {
190 if ( $i == $maxLogrotateFiles )
191 {
192 @unlink( $logRotateName );
193 }
194 else
195 {
196 $newLogRotateName = $fileName . '.' . ($i + 1);
197 eZFile::rename( $logRotateName, $newLogRotateName );
198 }
199 }
200 }
201 if ( file_exists( $fileName ) )
202 {
203 $newLogRotateName = $fileName . '.' . 1;
204 eZFile::rename( $fileName, $newLogRotateName );
205 return true;
206 }
207 return false;
208 }
209
214 static function setLogrotateFiles( $files )
215 {
216 $GLOBALS['eZMaxLogrotateFiles'] = $files;
217 }
218
219 }
220
221 ?>
$i
$i
Definition: admin/adlist.php:91
$message
$message
Definition: admin/message.php:51
$files
$files
Definition: articlepreview.php:91
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:546
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:74
eZFile\rename
static rename( $srcFile, $destFile, $mkdir=false, $flags=0)
Definition: ezfile.php:153
eZLog
Definition: ezlog.php:21
eZLog\MAX_LOGROTATE_FILES
const MAX_LOGROTATE_FILES
Definition: ezlog.php:22
eZLog\write
static write( $message, $logName='common.log', $dir='var/log')
Definition: ezlog.php:30
eZLog\setMaxLogSize
static setMaxLogSize( $size)
Definition: ezlog.php:147
eZLog\MAX_LOGFILE_SIZE
const MAX_LOGFILE_SIZE
Definition: ezlog.php:23
eZLog\writeStorageLog
static writeStorageLog( $name, $dir=false)
Definition: ezlog.php:72
eZLog\setLogrotateFiles
static setLogrotateFiles( $files)
Definition: ezlog.php:214
eZLog\rotateLog
static rotateLog( $fileName)
Definition: ezlog.php:178
eZLog\maxLogrotateFiles
static maxLogrotateFiles()
Definition: ezlog.php:156
eZLog\maxLogSize
static maxLogSize()
Definition: ezlog.php:128
$ini
$ini
Definition: classes/admin/linklist.php:64
$name
$name
Definition: companytypelist.php:194
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$fileName
if(eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user)==false) $fileName
Definition: ezfilemanager/user/filedownload.php:43
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
$time
$time
Definition: homepage.php:327
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.