Format a log message for a log file.

@param array $record
Log message array.
@return string Formatted log message followed by a line break.
358367
public static function format(array $record)
    {
        $seconds = (int) $record['time'];
        $millis = floor(($record['time'] - $seconds) * 1000);
        $timestamp = date('Y-m-d H:i:s', $seconds);
        $timestamp .= sprintf('.%03d ', $millis);
        $timestamp .= date('P');
        $level = '[' . $record['level'] . ']';
        $message = '';
        $message .= Logger::interpolate($record['message'], $record['context']);
        if (isset($record['context']['file'])) {
            $message .= ' in ' . $record['context']['file'];
        }
        if (isset($record['context']['line'])) {
            $message .= ' on line ' . $record['context']['line'];
        }
        return $timestamp . ' ' . $level . ' ' . $message . PHP_EOL;
    }
1204829
@Override
    public synchronized String format(LogRecord record) {
        StringBuilder sb = new StringBuilder();

        ZonedDateTime timestamp = ZonedDateTime.ofInstant(
                Instant.ofEpochMilli(record.getMillis()),
                ZoneId.systemDefault());

        sb.append(formatter.format(timestamp));
        sb.append(" | ");//$NON-NLS-1$

        if (record.getSourceClassName() != null) {
            sb.append(truncate(
                    record.getSourceClassName().substring(
                            record.getSourceClassName().lastIndexOf('.') + 1),
                    30));
        } else {
            sb.append(truncate(record.getLoggerName(), 10));
        }

        sb.append(" | "); //$NON-NLS-1$

        if (record.getSourceMethodName() != null) {
            sb.append(truncate(record.getSourceMethodName(), 30));
        }

        sb.append(" | "); //$NON-NLS-1$

        String message = formatMessage(record);
        sb.append(truncate(record.getLevel().getLocalizedName(), MAX_LEVEL_SIZE));

        sb.append(" | ");//$NON-NLS-1$

        sb.append(message);

        sb.append(System.getProperty("line.separator")); //$NON-NLS-1$
        if (record.getThrown() != null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            record.getThrown().printStackTrace(pw);
            pw.close();
            sb.append(sw.toString());
        }
        return sb.toString();
    }
1323020
protected function write(array $record)
    {
        $message = (string)$record['message'];
        $message = str_replace($this->build->currentBuildPath, '/', $message);

        $this->logValue .= $message . PHP_EOL;
        $this->build->setLog($this->logValue);

        Factory::getStore('Build')->save($this->build);
    }
230210
public function formatLog(array $logMessage) {
        extract($logMessage);

        $level = strtoupper($level);
        $message = $this->applyContext($message, $context);
        $timestamp = date($this->dateTimeFormat, $timestamp);
        $exception = $this->getExceptionTrace($context);

        $log = str_replace(self::FORMAT_TIMESTAMP, $timestamp, $this->logFormat);
        $log = str_replace(self::FORMAT_LEVEL, $level, $log);
        $log = str_replace(self::FORMAT_MESSAGE, $message, $log);
        $log = str_replace(self::FORMAT_EXCEPTION, $exception, $log);

        return $log;
    }
951488
public function getLogString(\Imi\Log\Record $record)
    {
        $vars = [
            'message'       => $record->getMessage(),
            'level'         => $record->getLevel(),
            'timestamp'     => $record->getLogTime(),
            'trace'         => $this->parseTrace($record),
        ];

        $find = $replace = [];
        foreach($vars as $key => $value)
        {
            if(is_scalar($value))
            {
                $find[] = '{' . $key . '}';
                $replace[] = $value;
            }
        }
        foreach ($record->getContext() as $key => $value)
        {
            if(is_scalar($value))
            {
                $find[] = '{' . $key . '}';
                $replace[] = $value;
            }
        }
        $logContent = str_replace($find, $replace, $this->format);
        
        return $this->replaceDateTime($logContent, $record->getLogTime());
    }
323851
private function formatRecord(array $records, $currentRecordIndex)
    {
        $record = $records[$currentRecordIndex];
        $recordAsString = '';

        if ($this->isLogInfoDisplayed($record)) {
            $logInfo = $this->formatLogInfo($record);
            $recordAsString .= $this->formatAsSection($logInfo);
        }

        if (isset($record['message']) && !empty($record['message'])) {
            $recordAsString .= $this->formatMessage($record).PHP_EOL;
        }

        if (isset($record['context']) && !empty($record['context'])) {
            // if the context contains an error stack trace, remove it to display it separately
            $stack = null;
            if (isset($record['context']['stack'])) {
                $stack = $record['context']['stack'];
                unset($record['context']['stack']);
            }

            $recordAsString .= $this->formatContext($record).PHP_EOL;

            if (null !== $stack) {
                $recordAsString .= '--> Stack Trace:'.PHP_EOL;
                $recordAsString .= $this->formatStackTrace($stack, '    | ');
            }
        }

        if (isset($record['extra']) && !empty($record['extra'])) {
            // don't display the extra information when it's identical to the previous log record
            $previousRecordExtra = isset($records[$currentRecordIndex - 1]) ? $records[$currentRecordIndex - 1]['extra'] : null;
            if ($record['extra'] !== $previousRecordExtra) {
                $recordAsString .= $this->formatExtra($record).PHP_EOL;
            }
        }

        return $recordAsString;
    }
332004
public function format( IRecord $record )
    {
        if ( !$record instanceof MailLogRecord )
        {
            throw new LogException( 'Record must be an instance of MailLogRecord' );
        }

        $title   = $record->getTitle();
        $heading = $record->getHeading();
        $body    = $record->getBody();

        $html =
            "<html>
                <head>
                    <title>$title</title>
                </head>
                <body>
                    <h1>$title</h1>
                    <h5>$heading</h5>
                    <p>$body</p>
                </body>
            </html>";

        return $html;
    }
1048116
protected function formatRecordsList(array $records)
    {
        return collect($records)->mapWithKeys(function ($attributes, $id) {
            if (!is_array($attributes)) {
                list($id, $attributes) = [$attributes, []];
            }

            return [$id => $attributes];
        })->all();
    }
713025
public function format( IRecord $record )
    {
        if ( !$record instanceof ErrorLogRecord )
        {
            throw new LogException( 'Record must be an instance of ErrorLogRecord' );
        }

        $format = '[%s] [%s] [%s] %s';

        $result = sprintf( $format,
                           $record->getDate()->format( 'D M d G:i:s T' ),
                           Log::getLevelString( $record->getLevel() ),
                           $record->getClientIP(),
                           $record->getText()
        );

        $result .= PHP_EOL;

        return $result;
    }
983507
protected function filterRecord(array $record)
    {
        foreach ($this->filteredKeys as $key) {
            if (isset($record[$key]) {
                unset($record[$key]);
            }
        }
        
        // Convert datetime object to string
        if (! isset($record['datetime'])) {
            $record['datetime'] = new \DateTime("now");
        }
        $record['datetime'] = $record['datetime']->format(self::DATE_FORMAT);

        return $record;
    }
653754
def format(self, record):
        """"""
        format_orig = self._fmt
        self._fmt = self.get_level_fmt(record.levelno)
        record.prefix = self.prefix
        record.plugin_id = self.plugin_id
        result = logging.Formatter.format(self, record)
        self._fmt = format_orig
        return result
1162265
public function parseMessage(\Imi\Log\Record $record): string
    {
        return str_replace($find, $replace, $record->getMessage());
    }
208633
protected function write(array $record) {
        $header = $this->getSyslogHeader($this->logLevels[$record['level']], $record['datetime']);
        $this->socket->write($record['formatted'], $header);
    }
1122206
protected function write(array $record)
    {
        if (!$this->initialized) {
            $this->initialize();
        }

        /**
         * reset $fields with default values
         */
        $this->fields = $this->defaultfields;

        /*
         * merge $record['context'] and $record['extra'] as additional info of Processors
         * getting added to $record['extra']
         * @see https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md
         */
        if (isset($record['extra'])) {
            $record['context'] = array_merge($record['context'], $record['extra']);
        }

        //'context' contains the array
        $contentArray = array_merge(array(
                                        'channel' => $record['channel'],
                                        'level' => $record['level'],
                                        'message' => $record['message'],
                                        'time' => $record['datetime']->format('U')
                                    ), $record['context']);

        // unset array keys that are passed put not defined to be stored, to prevent sql errors
        foreach($contentArray as $key => $context) {
            if (! in_array($key, $this->fields)) {
                unset($contentArray[$key]);
                unset($this->fields[array_search($key, $this->fields)]);
                continue;
            }

            if ($context === null) {
                unset($contentArray[$key]);
                unset($this->fields[array_search($key, $this->fields)]);
            }
        }

        $this->prepareStatement();

        //Fill content array with "null" values if not provided
        $contentArray = $contentArray + array_combine(
            $this->additionalFields,
            array_fill(0, count($this->additionalFields), null)
        );

        $this->statement->execute($contentArray);
    }
947341
protected function _format($log)
    {
        $replaced = [];

        $replaced[':date'] = date('Y-m-d\TH:i:s', $log->timestamp) . sprintf('.%03d', ($log->timestamp - (int)$log->timestamp) * 1000);
        $replaced[':client_ip'] = $log->client_ip ?: '-';
        $replaced[':request_id'] = $log->request_id ?: '-';
        $replaced[':request_id16'] = $log->request_id ? substr($log->request_id, 0, 16) : '-';
        $replaced[':category'] = $log->category;
        $replaced[':location'] = "$log->file:$log->line";
        $replaced[':level'] = strtoupper($log->level);
        if ($log->category === 'exception') {
            $replaced[':message'] = '';
            /** @noinspection SuspiciousAssignmentsInspection */
            $replaced[':message'] = preg_replace('#[\\r\\n]+#', '\0' . strtr($this->_format, $replaced), $log->message) . PHP_EOL;
        } else {
            $replaced[':message'] = $log->message . PHP_EOL;
        }

        return strtr($this->_format, $replaced);
    }
1279322
public function format(\Plop\RecordInterface $record)
    {
        /// @FIXME: use a different interpolator for the record's message?
        $record['message'] = $record->getMessage();
        $format = (string) $this->format;
        $dateFormat = (string) $this->dateFormat;
        if (strpos($format, '%(asctime)') !== false) {
            $record['asctime'] = $this->formatTime($record, $dateFormat);
        }

        $s = $this->interpolator->interpolate($format, $record->asArray());
        if ($record['exc_info']) {
            if (!$record['exc_text']) {
                $record['exc_text'] =
                    $this->formatException($record['exc_info']);
            }
        }
        if ($record['exc_text']) {
            $s .= "\n" . $record['exc_text'];
        }
        return $s;
    }
187427
protected function formatSyncList(array $records)
    {
        $results = array();

        foreach ($records as $id => $attributes)
        {
            if ( ! is_array($attributes))
            {
                list($id, $attributes) = array($attributes, array());
            }

            $results[$id] = $attributes;
        }

        return $results;
    }