Php logging implementation code. Copy the code as follows: $ ss_log_level0; $ ss_log_filenametmpss-log; $ ss_log_levelsarray (NONE0, ERROR1, INFO2, DEBUG3); set the log level funct
The code is as follows:
$ Ss_log_level = 0;
$ Ss_log_filename =/tmp/ss-log;
$ Ss_log_levels = array (
NONE => 0,
ERROR => 1,
INFO => 2,
DEBUG => 3
);
// Set the log level
Function ss_log_set_level ($ level = ERROR ){
Global $ ss_log_level;
$ Ss_log_level = $ level;
}
// Record logs
Function ss_log ($ level, $ message) {global $ ss_log_level, $ ss-log-filename;
If ($ ss_log_levels [$ ss_log_level] <$ ss_log_levels [$ level]) {
// Do not display Log information
Return false;
}
$ Fd = fopen ($ ss_log_filename, "a + ");
Fputs ($ fd, $ level.-[. ss_times ***** p_pretty ().]-. $ message. "n ");
Fclose ($ fd );
Return true;
}
// Clear logs
Function ss_log_reset (){
Global $ ss_log_filename;
@ Unlink ($ ss_log_filename );
}
// Call example
The code is as follows:
Ss_log_set_level (INFO );
Ss_log (ERROR, "testing level ERROR ");
Ss_log (INFO, "testing level INFO ");
Ss_log (DEBUG, "testing level DEBUG ");
Ss_log_reset ();
The http://www.bkjia.com/PHPjc/324033.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324033.htmlTechArticle code is as follows: $ ss_log_level = 0; $ ss_log_filename =/tmp/ss-log; $ ss_log_levels = array (NONE = 0, ERROR = 1, INFO = 2, DEBUG = 3); // Set the log level funct...