Location: PHPKode > projects > KvCMS Content Management System > kvframework/kvframework/logger/kvframework_log.class.php
<?php
load_file( KVF_FRAMEWORK_DIR."/logger/log_types/kvframework_logger.class.php", true);
load_file( KVF_FRAMEWORK_DIR."/logger/log_types/kvframework_console_logger.class.php", true);
load_file( KVF_FRAMEWORK_DIR."/logger/log_types/kvframework_email_logger.class.php", true);
load_file( KVF_FRAMEWORK_DIR."/logger/log_types/kvframework_local_logger.class.php", true);
load_file( KVF_FRAMEWORK_DIR."/logger/log_types/kvframework_syslog_logger.class.php", true);
load_file( KVF_FRAMEWORK_DIR."/logger/kvframework_log_session.class.php",true);
load_file( KVF_FRAMEWORK_DIR."/logger/kvframework_loginfo_struct.class.php",true);

define ("DEFAULT_LOCAL_LOGFILE_PATH", ROOTDIR."/log/");
define ("DEFAULT_EMAIL_SUBJECT", "LOG MESSAGE: ".date("r")); // The calling application is appended to the end of this.

abstract class kvframework_log{
  const DEFAULT_LOGGER_LOG_FACILITY = LOG_LOCAL6;
  const DEFAULT_MSG_SEVERITY = LOG_INFO;
  const DEFAULT_MSG_CATEGORY = "OTHER";
  const DEFAULT_THRESH = LOG_WARNING;
  const DEFAULT_MAX_QUEUE_SIZE = 250;
  const DEFAULT_ERROR_CONDITION_TRIGGER_THRESH = LOG_ERR;
  const DEFAULT_ERROR_CONDITION_THRESH = LOG_DEBUG;
  const DEFAULT_QUEUE_MODE = FALSE;
  const DEFAULT_LOCAL_LOGFILE_NAME = "crash.log";
  const DEFAULT_LOCAL_METHOD = "APPEND";
  const DEFAULT_EMAIL_RECIPIENT = "Greg McWhirter <hide@address.com>";
  const DEFAULT_EMAIL_SENDER = " Logger <hide@address.com>";
  const DEFAULT_SYSLOG_FACILITY = LOG_LOCAL6;

  const MESSAGE_CATEGORIES_LIST = "LDAP,DATA,SIS,LOGIC,FTP,LOGS,SQL,OTHER,INTERNAL";
  const SYSLOG_LEVELS_LIST = "KVF_LOG_LEMERG,KVF_LOG_LALERT,KVF_LOG_LCRITICAL,KVF_LOG_LERROR,KVF_LOG_LWARNING,KVF_LOG_LNOTICE,KVF_LOG_LINFO,KVF_LOG_LDEBUG";
  const LOG_MODES_LIST = "local,email,syslog,console";

  protected static $LOGSESSION;
  private static $LCONNECTED = false;
  public static $LOGS = array();
  protected static $LOGDEFAULT = null;

  final public static function start_logger(kvframework_loginfo_struct $loginfo, array $backlogs){
    if(!self::$LCONNECTED){
      self::$LOGSESSION = new kvframework_log_session("KvFramework");
      foreach($loginfo->types as $name => $type){
        self::$LOGS[$name] = self::$LOGSESSION->enable_log_instance($type);
      }
      foreach($loginfo->configs as $key => $params){
        $inst = "";
        foreach($params as $dir => $par){
          if(substr($key,0,2) == "n:"){
            $temp = substr($key, 2);
            $inst = self::$LOGS[$temp];
          } elseif(substr($key,0,2) == "t:"){
            $inst = substr($key,2);
          }

          if(is_null($par)){
            self::$LOGSESSION->configure_instance($inst, $dir);
          } else {
            self::$LOGSESSION->configure_instance($inst, $dir, $par);
          }

        }
      }
      self::$LOGDEFAULT = $loginfo->default;
      self::$LCONNECTED = true;

      foreach($backlogs as $log){
        call_user_func_array(array("self", "write_log"), $log);
      }
    }
  }

  final public static function write_log($message, $level = KVF_LOG_LINFO, array $logs = array(), $cat = null, array $forces = array()){
    $pars = array();
    if(count($logs) == 0){
      //print self::$LOGDEFAULT;
      $pars[0] = self::$LOGS[self::$LOGDEFAULT];
      foreach($forces as $f){
        $pars[] = $f;
      }
      if(!is_null($cat)){$pars[] = $cat;}
      $pars[] = $level;
      $pars[] = $message;

      //print_r($pars);
      call_user_func_array(array(self::$LOGSESSION, "log_entry"), $pars);
    } else {
      foreach($logs as $log){
        $pars[0] = self::$LOGS[$log];
        foreach($forces as $f){
          $pars[] = $f;
        }
        if(!is_null($cat)){$pars[] = $cat;}
        $pars[] = $level;
        $pars[] = $message;
        call_user_func_array(array(self::$LOGSESSION, "log_entry"), $pars);
      }
    }
  }

  final public static function close_logs(){
    self::$LOGSESSION->close_log();
    return true;
  }

}

?>
Return current item: KvCMS Content Management System