コード例 #1
0
ファイル: ezlog.php プロジェクト: CG77/ezpublish-legacy
 static function writeStorageLog($name, $dir = false)
 {
     $ini = eZINI::instance();
     $varDir = $ini->variable('FileSettings', 'VarDir');
     $logDir = $ini->variable('FileSettings', 'LogDir');
     $logName = 'storage.log';
     $fileName = $varDir . '/' . $logDir . '/' . $logName;
     $oldumask = @umask(0);
     clearstatcache(true, $fileName);
     $fileExisted = file_exists($fileName);
     if ($fileExisted and filesize($fileName) > eZLog::maxLogSize()) {
         if (eZLog::rotateLog($fileName)) {
             $fileExisted = false;
         }
     } else {
         if (!$fileExisted and !file_exists($varDir . '/' . $logDir)) {
             eZDir::mkdir($varDir . '/' . $logDir, false, true);
         }
     }
     if ($dir !== false) {
         $dir = preg_replace("#/\$#", "", $dir);
         $dir .= "/";
     } else {
         $dir = "";
     }
     $logFile = @fopen($fileName, "a");
     if ($logFile) {
         $time = strftime("%b %d %Y %H:%M:%S", strtotime("now"));
         $logMessage = "[ " . $time . " ] [" . $dir . $name . "]\n";
         @fwrite($logFile, $logMessage);
         @fclose($logFile);
         if (!$fileExisted) {
             $permissions = octdec($ini->variable('FileSettings', 'LogFilePermissions'));
             @chmod($fileName, $permissions);
         }
         @umask($oldumask);
     } else {
         eZDebug::writeError('Couldn\'t create the log file "' . $fileName . '"', __METHOD__);
     }
 }