PHP logging tool has not been written to php for a long time. I suddenly started an experiment and found that there was no log.
FileName = substr ($ filename, 0, $ dot_offset); else $ this-> FileName = $ filename; $ this-> FilePath = $ dir; $ this-> m_MaxLogFileNum = intval ($ maxlogfilenum); $ this-> m_RotaParam = intval ($ rotaparam); $ this-> m_RotaType = intval ($ rotatype ); $ this-> m_Priority = intval ($ priority); $ this-> m_LogCount = 0; $ this-> m_InitOk = $ this-> InitDir (); umask (0000 ); $ path = $ this-> createPath ($ this-> FilePath, $ this-> FileName ); If (! $ This-> isExist ($ path) {if (! $ This-> createDir ($ this-> FilePath) {# echo ("failed to create directory! ");} If (! $ This-> createLogFile ($ path) {# echo ("An error occurred while creating the file! ") ;}} Private function createPath ($ dir, $ file) {$ file = fopen ($ dir. DIRECTORY_SEPARATOR. $ file, 'w'); if ($ file) {fclose ($ file);} return $ dir. DIRECTORY_SEPARATOR. $ file;} private function InitDir () {if (is_dir ($ this-> FilePath) === false) {if (! $ This-> createDir ($ this-> FilePath) {// echo ("An error occurred while creating the directory! "); // Throw exception return false;} return true;} function console ($ priority, $ log) {if ($ this-> m_InitOk = false) return; if ($ priority> $ this-> m_Priority) return; $ path = $ this-> getLogFilePath ($ this-> FilePath, $ this-> FileName ). log: LOG_SUFFIXED; $ handle = fopen ($ path, "a +"); if ($ handle = false) {return ;} $ datestr = strftime ("% Y-% m-% d % H: % M: % S"); $ caller_info = $ this-> get_caller_info (); $ Status = fwrite ($ handle, $ caller_info. $ datestr. $ log. "\ n"); if (! $ Status) {// echo ("failed to write log");} fclose ($ handle); $ this-> RotaLog ();} /*** @ abstract write log * @ param String $ log content */function setLog ($ Log) {$ this-> console (log: NOTICE, $ log );} function LogDebug ($ log) {$ this-> console (Log: DEBUG, $ log);} function LogError ($ log) {$ this-> console (Log :: ERROR, $ log);} function LogNotice ($ log) {$ this-> console (Log: NOTICE, $ log);} private function get_caller_info () {$ ret = debug_backtrace (); foreach ($ ret as $ item) {if (isset ($ item ['class']) & 'logs' = $ item ['class']) {continue;} $ file_name = basename ($ item ['file']); return <GetLogFilePath ($ this-> FilePath, $ this-> FileName ). LOG: LOG_SUFFIXED; if ($ this-> m_LogCount % 10 = 0) clearstatcache (); ++ $ this-> m_LogCount; $ file_stat_info = stat ($ file_path ); if ($ file_stat_info = FALSE) return; if ($ this-> m_RotaType! = 1) return; // echo "file :". $ file_path. "". $ this-> m_RotaParam. "\ n"; if ($ file_stat_info ['size'] <$ this-> m_RotaParam) return; $ raw_file_path = $ this-> getLogFilePath ($ this-> FilePath, $ this-> FileName); $ file_path = $ raw_file_path. ($ this-> m_MaxLogFileNum-1 ). LOG: LOG_SUFFIXED; // echo "lastest file :". $ file_path. "\ n"; if ($ this-> isExist ($ file_path) {unlink ($ file_path) ;}for ($ I = $ this-> m_MaxLogFileNum-2; $ I> = 0; $ I --) {if ($ I = 0) $ file_path = $ raw_file_path.LOG: LOG_SUFFIXED; else $ file_path = $ raw_file_path. $ I. LOG: LOG_SUFFIXED; if ($ this-> isExist ($ file_path) {$ new_file_path = $ raw_file_path. ($ I + 1 ). LOG: LOG_SUFFIXED; if (rename ($ file_path, $ new_file_path) <0) {continue ;}}} function isExist ($ path) {return file_exists ($ path );} /*** @ abstract: create a directory * @ param
$ Dir directory name * @ return bool */function createDir ($ dir) {// Determine whether the directory has return is_dir ($ dir) or ($ this-> createDir (dirname ($ dir) and mkdir ($ dir, 0777 ));} /*** @ abstract create a log file * @ param String $ path * @ return bool */function createLogFile ($ path) {$ handle = fopen ($ path, "w"); // create a file if ($ handle) {fclose ($ handle);} return $ this-> isExist ($ path );} /*** @ abstract creation path * @ param String $ dir directory name * @ param String $ Filename */function getLogFilePath ($ dir, $ filename) {return $ dir. "/". $ filename ;}}?>