Exemple #1
0
/**
 * 简化日志写入方法
 *
 * @see    http://docs.phalconphp.com/en/latest/api/Phalcon_Logger.html
 * @see    http://docs.phalconphp.com/en/latest/api/Phalcon_Logger_Adapter_File.html
 * @param  string $name 日志名称
 * @param  string $message 日志内容
 * @param  string $type 日志类型
 * @param  boolean $addUrl 记录当前 url
 * @return Phalcon\Logger\Adapter\File
 */
function write_log($name, $message, $type = null, $addUrl = false)
{
    static $logger, $formatter;
    if (!isset($logger[$name])) {
        $logfile = DATA_PATH . '/logs/' . date('/Ym/') . $name . '_' . date('Ymd') . '.log';
        if (!is_dir(dirname($logfile))) {
            mkdir(dirname($logfile), 0755, true);
        }
        $logger[$name] = new Phalcon\Logger\Adapter\File($logfile);
        // Set the logger format
        if ($formatter === null) {
            $formatter = new Phalcon\Logger\Formatter\Line();
            $formatter->setDateFormat('Y-m-d H:i:s O');
        }
        $logger[$name]->setFormatter($formatter);
    }
    if ($type === null) {
        $type = Phalcon\Logger::INFO;
    }
    if ($addUrl) {
        $logger[$name]->log('URL: ' . HTTP_URL, Phalcon\Logger::INFO);
    }
    $logger[$name]->log($message, $type);
    return $logger[$name];
}
Exemple #2
0
 public function testIssues10631()
 {
     $logger = new \Phalcon\Logger\Formatter\Line();
     $result = $logger->format("msg", \Phalcon\Logger::INFO, 0);
     $this->assertEquals($result, '[Thu, 01 Jan 70 00:00:00 +0000][INFO] msg' . PHP_EOL);
 }