From d10727797bcf28e43fcd57fc56458c69b91e9363 Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Tue, 8 May 2012 18:13:38 +0700 Subject: [PATCH] new ConsoleLog logging engine --- lib/Cake/Log/Engine/ConsoleLog.php | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 lib/Cake/Log/Engine/ConsoleLog.php diff --git a/lib/Cake/Log/Engine/ConsoleLog.php b/lib/Cake/Log/Engine/ConsoleLog.php new file mode 100644 index 000000000..f3eb32f02 --- /dev/null +++ b/lib/Cake/Log/Engine/ConsoleLog.php @@ -0,0 +1,78 @@ + 'php://stderr', + 'types' => null, + 'outputAs' => ConsoleOutput::COLOR, + ), $this->_config); + $config = $this->config($config); + if ($config['stream'] instanceof ConsoleOutput) { + $this->_output = $config['stream']; + } elseif (is_string($config['stream'])) { + $this->_output = new ConsoleOutput($config['stream']); + } else { + throw new CakeLogException('`stream` not a ConsoleOutput nor string'); + } + $this->_output->outputAs($config['outputAs']); + } + +/** + * Implements writing to console. + * + * @param string $type The type of log you are making. + * @param string $message The message you want to log. + * @return boolean success of write. + */ + public function write($type, $message) { + $output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n"; + return $this->_output->write(sprintf('<%s>%s', $type, $output, $type), false); + } + +}