本文整理汇总了PHP中Zend_Log_Writer_Stream::setFormatter方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Log_Writer_Stream::setFormatter方法的具体用法?PHP Zend_Log_Writer_Stream::setFormatter怎么用?PHP Zend_Log_Writer_Stream::setFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Log_Writer_Stream
的用法示例。
在下文中一共展示了Zend_Log_Writer_Stream::setFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
/**
* Setup db
*
*/
public function setup(Zend_Config $config)
{
// Get resource config
$writerConfig = $config->writer;
$filterConfig = $config->filter;
// Log instance
$log = new Zend_Log();
// Enable database writer?
if ($writerConfig->database->enabled) {
$db = $this->getRegistry()->get($writerConfig->database->key, 'Zend_Db_Adapter_Abstract');
// Make sure it's a right object
if (!$db instanceof Zend_Db_Adapter_Abstract) {
require_once 'Zym/App/Resource/Exception.php';
throw new Zym_App_Resource_Exception('Resource ' . get_class($this) . ' requires the internal registry item "db" to contain a Zend_Db_Adapter_Abstract object');
}
$dbWriter = new Zend_Log_Writer_Db($db, $writerConfig->database->table);
$log->addWriter($dbWriter);
}
// Enable stream writer?
if ($writerConfig->stream->enabled) {
$streamWriter = new Zend_Log_Writer_Stream($writerConfig->stream->stream, $writerConfig->stream->mode);
$streamWriter->setFormatter(new Zend_Log_Formatter_Simple('%timestamp% %ipAddr% %priorityName% (%priority%): %message%' . PHP_EOL));
$log->addWriter($streamWriter);
}
// Enable null writer
$log->addWriter(new Zend_Log_Writer_Null());
// Setup filters
// Priority filter
if ($filterConfig->priority->enabled) {
$log->addFilter(new Zend_Log_Filter_Priority((int) $filterConfig->priority->level));
}
// Setup events
// Log user ip address
//$log->setEventItem('ipAddr', $_SERVER['REMOTE_ADDR']);
}
示例2: addWriteToScreen
function addWriteToScreen()
{
parent::addWriteToScreen();
$writerScreen = new Zend_Log_Writer_Stream('php://stderr');
$writerScreen->setFormatter( $this->screenFormatter );
$this->addWriter($writerScreen);
}
示例3: preDispatch
public function preDispatch($request)
{
try {
$locale = new Zend_Locale();
$locale->setDefault('en');
$locale->setLocale(Zend_Locale::BROWSER);
$requestedLanguage = key($locale->getBrowser());
$formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
$writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'translations.log');
$writer->setFormatter($formatter);
$logger = new Zend_Log($writer);
$frontendOptions = array('cache_id_prefix' => 'translation', 'lifetime' => 86400, 'automatic_serialization' => true);
$backendOptions = array('cache_dir' => APPLICATION_CACHE_PATH);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
$options = array('adapter' => 'gettext', 'scan' => Zend_Translate::LOCALE_FILENAME, 'content' => APPLICATION_PATH . '/languages/en/en.mo', 'locale' => 'auto', 'disableNotices' => true);
$translate = new Zend_Translate($options);
if (!$translate->isAvailable($locale->getLanguage())) {
$locale->setLocale('en');
} else {
$translate->setLocale($locale);
}
$translate->setCache($cache);
Zend_Registry::set('locale', $locale->getLanguage());
Zend_Registry::set('Zend_Translate', $translate);
} catch (Exception $e) {
try {
$writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'plugin-locale.log');
$logger = new Zend_Log($writer);
$logger->log($e->getMessage(), Zend_Log::ERR);
} catch (Exception $e) {
}
}
}
示例4: log
private function log()
{
$dir = APP_PATH . '/logs/request';
if (!is_dir($dir)) {
mkdir($dir, 0755);
}
$file = $dir . '/' . date('Y-m-d') . '.log';
$logger = new \Zend_Log();
$formatter = new \Zend_Log_Formatter_Simple("%message%\n");
$writer = new \Zend_Log_Writer_Stream($file);
$writer->setFormatter($formatter);
$logger->addWriter($writer);
$data = array();
$data[] = '[' . date('Y-m-d H:i:s') . '] ';
$url = Http::getUrl('current');
$url = substr($url, 0, strpos($url, '?')) . '?' . http_build_query($this->getRequest()->getRequest());
$data[] = $url;
$line = implode('', $data);
$debug = Application::app()->getConfig()->debug;
if ($debug) {
$res = $this->getResponse()->getBody('api');
$line .= "\n\t" . $res;
}
$logger->log($line, $logger::NOTICE);
}
示例5: initDefault
public static function initDefault($logFilePath)
{
$writer = new Zend_Log_Writer_Stream($logFilePath);
$format = '[%timestamp%] [%priorityName% %priority%] %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
$writer->setFormatter($formatter);
Logger::registerLogger('default', $writer, null, true);
}
示例6: addStreamWriter
/**
* Add a stream writer
*
* @param array $params
* @param object $formatter
* @return void
*/
public function addStreamWriter($params = array(), Zend_Log_Formatter_Interface $formatter = null)
{
$writer = new Zend_Log_Writer_Stream($params['file_path_url'], $params['mode']);
if ($formatter) {
$writer->setFormatter($formatter);
}
$this->addWriter($writer);
}
示例7: initLogger
/**
* Initialise the logger with the given file.
*/
private function initLogger($logfileName)
{
$logfile = @fopen($logfileName, 'a', false);
$writer = new Zend_Log_Writer_Stream($logfile);
$formatter = new Zend_Log_Formatter_Simple('%priorityName%: %message%' . PHP_EOL);
$writer->setFormatter($formatter);
$this->logger = new Zend_Log($writer);
}
示例8: getWriter
private static function getWriter(Zend_Config $config)
{
if ($config->name === null) {
return null;
}
$writer = null;
switch ($config->name) {
case "Zend_Log_Writer_Stream":
if ($config->stream === null) {
return null;
}
if ($config->mode === null) {
$mode = 'a';
}
$writer = new Zend_Log_Writer_Stream($config->stream, $mode);
break;
}
if ($writer !== null && $config->formatters !== null) {
foreach ($config->formatters as $formatterConfig) {
$formatter = self::getFormatter($formatterConfig);
if ($formatter !== null) {
$writer->setFormatter($formatter);
}
}
}
if ($writer !== null && $config->formatters !== null) {
foreach ($config->formatters as $formatterConfig) {
$formatter = self::getFormatter($formatterConfig);
if ($formatter !== null) {
$writer->setFormatter($formatter);
}
}
}
if ($writer !== null && $config->filters !== null) {
foreach ($config->filters as $filterConfig) {
$formatter = self::getFilter($filterConfig);
if ($formatter !== null) {
$writer->addFilter($formatter);
}
}
}
return $writer;
}
示例9: _initLog
/**
* set logger
* @return void
*/
protected function _initLog()
{
// Error log
$writer = new Zend_Log_Writer_Stream($this->_config->logpath);
$format = '%timestamp% %priorityName% (%priority%): ' . '[%module%] [%controller%] %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
$writer->setFormatter($formatter);
$logger = new Zend_Log($writer);
Zend_Registry::getInstance()->set('logger', $logger);
}
示例10: _allWriter
/**
* Writer untuk log message yang lainnya
* Log message yang lainnya akan dituliskan ke dalam file system.log
*/
protected function _allWriter()
{
$log = ROOT_DIR . '/data/log/system.log';
$stream = fopen($log, 'a', false);
if (!$stream) {
throw new Exception('Failed to open _writer stream');
}
$writer = new Zend_Log_Writer_Stream($stream);
$writer->setFormatter($this->_formatter);
return $writer;
}
示例11: saveCdrBanners
private function saveCdrBanners($datos, $id, $name)
{
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../logs/cdr/' . $name . ".banners");
// $writer = new Zend_Log_Writer_Stream('/var/log/portalwap/'.$name.".banners");
$formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
$writer->setFormatter($formatter);
$log = new Zend_Log($writer);
$banners = 'banner1.' . $datos['url'][0] . "," . 'banner2.' . $datos['url'][1] . "," . 'banner3.' . $datos['url'][2] . "," . 'banner4.' . $datos['url'][3] . "," . 'banner5.' . $datos['url'][4];
$mensaje = $datos['fecha'] . "," . $datos['hora'] . "," . $_SERVER['REMOTE_ADDR'] . "," . $datos['telefono'] . ",perfil:" . $datos['perfil'] . "," . $banners;
$log->info($mensaje);
}
示例12: saveLog
protected function saveLog($errors)
{
$logger = new Zend_Log();
$writer = new Zend_Log_Writer_Stream('application/tmp/erro/error.xml');
$formatter = new Zend_Log_Formatter_Xml();
$writer->setFormatter($formatter);
$logger->addWriter($writer);
$exception = $errors->exception;
$exception->getTraceAsString();
$logger->debug($exception->getMessage() . "\r\n");
}
示例13: saveCdrLog
public function saveCdrLog($url, $message, $portal)
{
$datos = $this->obtenerPerfilNumero();
$name = date('YmdH');
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../data/cdr/' . $portal . '/' . $name . ".log");
$formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
$writer->setFormatter($formatter);
$log = new Zend_Log($writer);
$mensaje = $datos['fecha'] . "," . $datos['hora'] . "," . 'PERFIL:' . $datos['perfil'] . "," . $url . "," . $message . "," . $datos['telefono'];
$log->info($mensaje);
}
示例14: saveCdrDedicatorias
public function saveCdrDedicatorias($resultado)
{
$name = date('YmdH');
$datos = $this->registerCdr();
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../logs/cdr/' . $name . ".dedicatoria");
$formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
$writer->setFormatter($formatter);
$log = new Zend_Log($writer);
$mensaje = $datos['fecha'] . "," . $datos['hora'] . "," . $_SERVER['REMOTE_ADDR'] . "," . $datos['telefono'] . "," . 'perfil:' . $datos['perfil'] . "," . $resultado;
$log->info($mensaje);
}
示例15: _setupLog
/**
* Initialize the logger. You may want to override the function
*
* @return void
*/
protected function _setupLog()
{
$this->logger = new Streamwide_Log();
$this->logger->setEventItem("class", get_class($this));
$writer = new Zend_Log_Writer_Stream("php://output");
$format = "SW | %class% | %timestamp% | %pid% | %memory% | %duration% | %priorityName%: %message%<br/>" . PHP_EOL;
$formater = new Zend_Log_Formatter_Simple($format);
$writer->setFormatter($formater);
//$writer->addFilter(new Streamwide_Log_Filter_Priority(LOGGER_INFO));
$this->logger->addWriter($writer);
}