1

I am using the yii log facility to log some important events. Does any one has an idea how change the log layout in yii ?

1 Answer 1

2

You can extend CFileLogRoute and rewrite formatLogMessage method. Example:

class YourFileLogRoute extends CFileLogRoute
{

    ...

    /**
     * Formats a log message given different fields.
     * @param string $message message content
     * @param integer $level message level
     * @param string $category message category
     * @param integer $time timestamp
     * @return string formatted message
     */
    protected function formatLogMessage($message, $level = 'I', $category = null, $time = null)
    {
        if ($time === null)
            $time = time();

        $level = strtoupper($level[0]);

        return @date( 'M d H:i:s', $time ) . ' [' . sprintf( '%-30s', $category ) . '] ' . ': <' . $level . '> ' . $message . PHP_EOL;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.