phpログの実現コード

1203 ワード

 
$ss_log_level = 0;

  $ss_log_filename = /tmp/ss-log;

  $ss_log_levels = array(
   NONE => 0,
   ERROR => 1,
   INFO => 2,
   DEBUG => 3
);

//
  function ss_log_set_level ($level = ERROR) {
   global $ss_log_level;
   $ss_log_level = $level;
  }

//

function ss_log ($level, $message) {    global $ss_log_level, $ss-log-filename;

   if ($ss_log_levels[$ss_log_level] < $ss_log_levels[$level]) {
   // Log
   return false;
   }

   $fd = fopen($ss_log_filename, "a+");
   fputs($fd, $level. - [.ss_times*****p_pretty().] - .$message."n");
   fclose($fd);
   return true;
  }

//
  function ss_log_reset () {
   global $ss_log_filename;
   @unlink($ss_log_filename);
  }
/呼び出し例
 
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();