private function printToFile($log)
    {
        if (!is_string($log['message']))
            $log['message'] = json_encode($log['message']);
        
        $toPrint = $log['time'] . " [" . $log['type'] . "] [" . $log['source'] . "] ";
        // If there is a workflow ID. We append it.
        if (isset($log['logKey']) && $log['logKey'])
            $toPrint .= "[".$log['logKey']."] ";
        $toPrint .= $log['message'] . "\n";

        if ($this->printout)
            print $toPrint;
        
        if (file_put_contents(
                $this->filePath,
                $toPrint,
                FILE_APPEND) === false) {
            throw new CpeException("Can't write into log file: $this->logPath", 
                LOGFILE_ERROR);
        }
    }