private function log($priority, $msg, $fileHandle = null)
    {
        if ($priority[0] < $this->logLevel && $fileHandle === null) {
            return;
        }

        $logTime = time();

        $this->logQueue[] = new Logger\Message($priority[1], $logTime, $msg);

        /* ensure the output messages line up vertically */
        $prioritystr = '['.$priority[1].']';
        $timestr = '['.date('Y-m-d H:i:s - T', $logTime).']';
        while (strlen($prioritystr) < 7) {
            $prioritystr .= ' ';
        }
        $message = $prioritystr.'  '.$timestr.' '.$msg."\n";
        $message = getmypid().': '.$message;

        if (defined('STDERR')) {
            fputs(STDERR, getmypid().': '.$prioritystr.'  '.$msg."\n");
        } else {
            echo '<!-- LogMessage: '.$message." -->\n";
        }

        if ($this->file != null) {
            if ($fileHandle !== null) {
                fputs($fileHandle, $message);
            } else {
                error_log($message, 3, $this->file);
            }
        } elseif ($fileHandle !== null) {
            fputs($fileHandle, $message);
        }

        if (count($this->logQueue) > $this->max) {
            $this->flush();
        }
    }