当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Log::setTimestampFormat方法代码示例

本文整理汇总了PHP中Zend_Log::setTimestampFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Log::setTimestampFormat方法的具体用法?PHP Zend_Log::setTimestampFormat怎么用?PHP Zend_Log::setTimestampFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Log的用法示例。


在下文中一共展示了Zend_Log::setTimestampFormat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testLogWritesWithModifiedTimestampFormat

 /**
  * @group ZF-9870
  */
 public function testLogWritesWithModifiedTimestampFormat()
 {
     $logger = new Zend_Log($this->writer);
     $logger->setTimestampFormat('Y-m-d');
     $logger->debug('ZF-9870');
     rewind($this->log);
     $message = stream_get_contents($this->log);
     $this->assertEquals(date('Y-m-d'), substr($message, 0, 10));
 }
开发者ID:crodriguezn,项目名称:crossfit-milagro,代码行数:12,代码来源:LogTest.php

示例2: caSetupCLIScript

/**
 * Do general setup for a CLI script
 * @param array $pa_additional_parameters Additional command line parameters. You don't have to add
 * --log/-l for the log file and --log-level/-d for the Zend_Log log level. They're always set up automatically
 * @return Zend_Console_Getopt
 */
function caSetupCLIScript($pa_additional_parameters)
{
    require_once __CA_LIB_DIR__ . "/core/Zend/Console/Getopt.php";
    require_once __CA_LIB_DIR__ . "/core/Zend/Log.php";
    require_once __CA_LIB_DIR__ . "/core/Zend/Log/Writer/Stream.php";
    require_once __CA_LIB_DIR__ . "/core/Zend/Log/Writer/Syslog.php";
    require_once __CA_LIB_DIR__ . "/core/Zend/Log/Formatter/Simple.php";
    $va_available_cli_opts = array_merge(array("log|l-s" => "Path to log file. If omitted, we log into the system log. Note that we don't log DEBUG messages into the system log, even when the log level is set to DEBUG.", "log-level|d-s" => "Log level"), $pa_additional_parameters);
    try {
        $o_opts = new Zend_Console_Getopt($va_available_cli_opts);
        $o_opts->parse();
    } catch (Exception $e) {
        die("Invalid command line options: " . $e->getMessage() . PHP_EOL);
    }
    // set up logging
    $o_writer = null;
    if ($vs_log = $o_opts->getOption('log')) {
        // log to file
        try {
            $o_writer = new Zend_Log_Writer_Stream($vs_log);
            $o_writer->setFormatter(new Zend_Log_Formatter_Simple('%timestamp% %priorityName%: %message%' . PHP_EOL));
        } catch (Zend_Log_Exception $e) {
            // error while opening the file (usually permissions)
            $o_writer = null;
            print CLIUtils::textWithColor("Couldn't open log file. Now logging via system log.", "bold_red") . PHP_EOL . PHP_EOL;
        }
    }
    // default: log everything to syslog
    if (!$o_writer) {
        $o_writer = new Zend_Log_Writer_Syslog(array('application' => 'CollectiveAccess CLI', 'facility' => LOG_USER));
        // no need for timespamps in syslog ... the syslog itsself provides that
        $o_writer->setFormatter(new Zend_Log_Formatter_Simple('%priorityName%: %message%' . PHP_EOL));
    }
    // was a loglevel set via command line? -> add filter to Zend logger, otherwise use WARN
    $vs_level = $o_opts->getOption('log-level');
    switch ($vs_level) {
        case 'ERR':
            $o_filter = new Zend_Log_Filter_Priority(Zend_Log::ERR);
            break;
        case 'DEBUG':
            $o_filter = new Zend_Log_Filter_Priority(Zend_Log::DEBUG);
            break;
        case 'INFO':
            $o_filter = new Zend_Log_Filter_Priority(Zend_Log::INFO);
            break;
        case 'WARN':
        default:
            $o_filter = new Zend_Log_Filter_Priority(Zend_Log::WARN);
            break;
    }
    // set up global logger. can be used by importing 'global $g_logger' anywhere, but it's recommended to use the caCLILog() helper instead
    global $g_logger;
    $g_logger = new Zend_Log($o_writer);
    $g_logger->setTimestampFormat('D Y-m-d H:i:s');
    $g_logger->addFilter($o_filter);
    return $o_opts;
}
开发者ID:idiscussforum,项目名称:providence,代码行数:63,代码来源:CLIHelpers.php

示例3: getLog

 /**
  * Obtem um objeto Zend_Log
  * @return \Zend_Log
  */
 protected function getLog()
 {
     $logger = new \Zend_Log($this->getWriteLog());
     $logger->setTimestampFormat("d/m/Y H:i:s");
     return $logger;
 }
开发者ID:avandrevitor,项目名称:S9,代码行数:10,代码来源:Logging.php


注:本文中的Zend_Log::setTimestampFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。