php记录日志的实现代码

前端之家收集整理的这篇文章主要介绍了php记录日志的实现代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="85436" class="copybut" id="copybut85436" onclick="doCopy('code85436')"> 代码如下:

<div class="codebody" id="code85436">
$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);
  }
   //调用示例
<div class="codetitle"><a style="CURSOR: pointer" data="77150" class="copybut" id="copybut77150" onclick="doCopy('code77150')"> 代码如下:
<div class="codebody" id="code77150">
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();

原文链接:https://www.f2er.com/php/27692.html

猜你在找的PHP相关文章