Location: PHPKode > projects > KvCMS Content Management System > kvframework/kvframework/logger/log_types/kvframework_local_logger.class.php
<?php
class kvframework_local_logger extends kvframework_logger
{
    protected $logfile_path;
    protected $logfile_name;
    protected $logfile;
    protected $mode;
    protected $file_pointer;

    public function __construct(&$parent_logger_instance, $parent_application)
    {
        parent::__construct ($parent_logger_instance, $parent_application);
        $this->local_set_logfile_path(DEFAULT_LOCAL_LOGFILE_PATH);
        $this->local_set_logfile_name(kvframework_log::DEFAULT_LOCAL_LOGFILE_NAME);
        $this->file_pointer = FALSE;
        $this->type = "local";
    }

    public function local_set_logfile_mode ($mode)
    {
        $this->mode = $mode;
    }

    public function local_set_logfile_name($logfile_name)
    {
        $this->filename = $logfile_name;
        $this->needs_reset = TRUE;
    }

    public function local_set_logfile_path($logfile_path)
    {
        if ( substr ($logfile_path, strlen($logfile_path) - 1) !== "/" )
        {
            $logfile_path = $logfile_path."/";
        }
        $this->path = $logfile_path;
        $this->needs_reset = TRUE;
    }

    public function type_specific_reset()
    {
        $this->log_file = $this->path.$this->filename;
    }

    public function type_specific_open()
    {
        if (file_exists($this->log_file))
        {
            if ($this->mode == "ARCHIVE")
            {
                rename($this->log_file, $this->log_file.date("Ymd-Gis"));
            }
        }
        if ($this->file_pointer = fopen ($this->log_file, "a+"))
        {
            $entry["MSG_TIME"] = date("r");
            $entry["MSG_CATEGORY"] = "LOGS";
            $entry["MSG_SEVERITY"] = KVF_LOG_LINFO;
            $entry["MSG_MSG"] = "LOG OPENED, REQUESTED BY APPLICATION ".$this->parent_application;
            $this->type_specific_output_msg($entry);
        }
        else
        {
            $log_error_msg = "Unable to open log file ".$this->filename;
            parent::write_logger_log($log_error_msg);
            return (FALSE);
        }
        return (TRUE);
    }

    public function type_specific_output_msg($entry)
    {
        // We have to pull this out because php doesn't like to use an array as an index to another array
        $severity = $entry["MSG_SEVERITY"];
        fputs ($this->file_pointer, str_pad($entry["MSG_TIME"], 36).str_pad($entry["MSG_CATEGORY"], 13).str_pad($this->syslog_levels[$severity], 13).$entry["MSG_MSG"]."\n");
    }

    public function type_specific_close()
    {
        return ( fclose ($this->file_pointer) );
    }

}
?>
Return current item: KvCMS Content Management System