public function logOut(
        $type,
        $source,
        $message,
        $logKey = null,
        $printOut = true)
    {
        $log = [
            "time"    => date("Y-m-d H:i:s", time()),
            "source"  => $source,
            "type"    => $type,
            "message" => $message
        ];

        if ($printOut)
            $this->printOut = $printOut;
    
        if ($logKey)
            $log["logKey"] = $logKey;

        // Set the log filaname based on the logkey If provided.
        // If not then it will log in a file that has the name of the PHP activity file
        $file = $this->activityName;
        // Append progname to the path
        $this->filePath = $this->logPath . "/" . $file.".log";

        // Open Syslog. Use programe name as key
        if (!openlog (__FILE__, LOG_CONS|LOG_PID, LOG_LOCAL1))
            throw new CpeException("Unable to connect to Syslog!",
                OPENLOG_ERROR);
        
        // Change Syslog priority level
        switch ($type)
        {
        case "INFO":
            $priority = LOG_INFO;
            break;
        case "ERROR":
            $priority = LOG_ERR;
            break;
        case "FATAL":
            $priority = LOG_ALERT;
            break;
        case "WARNING":
            $priority = LOG_WARNING;
            break;
        case "DEBUG":
            $priority = LOG_DEBUG;
            break;
        default:
            throw new CpeException("Unknown log Type!", 
                LOG_TYPE_ERROR);
        }
        
        // Print log in file
        $this->printToFile($log);
        
        // Encode log message in JSON for better parsing
        $out = json_encode($log);
        // Send to syslog
        syslog($priority, $out);
    }
public function logOut(
        $type,
        $source,
        $message,
        $logKey = null,
        $printOut = true)
    {
        $log = [
            "time"    => date("Y-m-d H:i:s", time()),
            "source"  => $source,
            "type"    => $type,
            "message" => $message
        ];

        if ($printOut)
            $this->printOut = $printOut;
    
        if ($logKey)
            $log["logKey"] = $logKey;

        // Set the log filaname based on the logkey If provided.
        // If not then it will log in a file that has the name of the PHP activity file
        $file = $this->activityName;
        // Append progname to the path
        $this->filePath = $this->logPath . "/" . $file.".log";

        // Open Syslog. Use programe name as key
        if (!openlog (__FILE__, LOG_CONS|LOG_PID, LOG_LOCAL1))
            throw new CpeException("Unable to connect to Syslog!",
                OPENLOG_ERROR);
        
        // Change Syslog priority level
        switch ($type)
        {
        case "INFO":
            $priority = LOG_INFO;
            break;
        case "ERROR":
            $priority = LOG_ERR;
            break;
        case "FATAL":
            $priority = LOG_ALERT;
            break;
        case "WARNING":
            $priority = LOG_WARNING;
            break;
        case "DEBUG":
            $priority = LOG_DEBUG;
            break;
        default:
            throw new CpeException("Unknown log Type!", 
                LOG_TYPE_ERROR);
        }
        
        // Print log in file
        $this->printToFile($log);
        
        // Encode log message in JSON for better parsing
        $out = json_encode($log);
        // Send to syslog
        syslog($priority, $out);
    }
public function logOut ( $ type , $ source , $ message , $ logKey = null , $ printOut = true ) { $ log = [ "time" => date ( "Y-m-d H:i:s" , time ( ) ) , "source" => $ source , "type" => $ type , "message" => $ message ] ; if ( $ printOut ) $ this -> printOut = $ printOut ; if ( $ logKey ) $ log [ "logKey" ] = $ logKey ; // Set the log filaname based on the logkey If provided. // If not then it will log in a file that has the name of the PHP activity file $ file = $ this -> activityName ; // Append progname to the path $ this -> filePath = $ this -> logPath . "/" . $ file . ".log" ; // Open Syslog. Use programe name as key if ( ! openlog ( __FILE__ , LOG_CONS | LOG_PID , LOG_LOCAL1 ) ) throw new CpeException ( "Unable to connect to Syslog!" , OPENLOG_ERROR ) ; // Change Syslog priority level switch ( $ type ) { case "INFO" : $ priority = LOG_INFO ; break ; case "ERROR" : $ priority = LOG_ERR ; break ; case "FATAL" : $ priority = LOG_ALERT ; break ; case "WARNING" : $ priority = LOG_WARNING ; break ; case "DEBUG" : $ priority = LOG_DEBUG ; break ; default : throw new CpeException ( "Unknown log Type!" , LOG_TYPE_ERROR ) ; } // Print log in file $ this -> printToFile ( $ log ) ; // Encode log message in JSON for better parsing $ out = json_encode ( $ log ) ; // Send to syslog syslog ( $ priority , $ out ) ; }
Log message to syslog and log file. Will print
Log message to syslog and log file . Will print