本文整理汇总了PHP中Zend_Log::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Log::factory方法的具体用法?PHP Zend_Log::factory怎么用?PHP Zend_Log::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Log
的用法示例。
在下文中一共展示了Zend_Log::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFactory
public function testFactory()
{
$cfg = array('log' => array('memory' => array('writerName' => "Null")));
require_once 'Zend/Log.php';
$logger = Zend_Log::factory($cfg['log']);
$this->assertTrue($logger instanceof Zend_Log);
}
示例2: log
/**
* 记录日志(等级,消息,文件前缀-分组)
* Enter description here ...
* @param $level
* @param $message
* @param $filename
*/
function log($level, $message, $filename = 'application')
{
require_once 'Zend/Log.php';
@mkdir(APPPATH . './logs/' . substr($filename, 0, strrpos($filename, '/')), 0777, 1);
$logger = Zend_Log::factory(array('timestampFormat' => 'Y-m-d H:i:s', array('writerName' => 'Stream', 'writerParams' => array('stream' => APPPATH . '/logs/' . $filename . '-' . date('Y-m-d') . '.log'), 'formatterName' => 'Simple', 'formatterParams' => array('format' => '%timestamp%: %message%' . PHP_EOL), 'filterName' => 'Priority', 'filterParams' => array('priority' => Zend_Log::DEBUG))));
$logger->log($message, $level);
}
示例3: getTranslate
/**
* Retrieve translate object
*
* @return Zend_Translate
* @throws Zend_Application_Resource_Exception if registry key was used
* already but is no instance of Zend_Translate
*/
public function getTranslate()
{
if (null === $this->_translate) {
$options = $this->getOptions();
if (!isset($options['content']) && !isset($options['data'])) {
require_once LIB_DIR . '/Zend/Application/Resource/Exception.php';
throw new Zend_Application_Resource_Exception('No translation source data provided.');
} else {
if (array_key_exists('content', $options) && array_key_exists('data', $options)) {
require_once LIB_DIR . '/Zend/Application/Resource/Exception.php';
throw new Zend_Application_Resource_Exception('Conflict on translation source data: choose only one key between content and data.');
}
}
if (empty($options['adapter'])) {
$options['adapter'] = Zend_Translate::AN_ARRAY;
}
if (!empty($options['data'])) {
$options['content'] = $options['data'];
unset($options['data']);
}
if (isset($options['log'])) {
if (is_array($options['log'])) {
$log = Zend_Log::factory($options['log']);
}
if ($log instanceof Zend_Log) {
$options['log'] = $log;
}
}
if (isset($options['options'])) {
foreach ($options['options'] as $key => $value) {
$options[$key] = $value;
}
}
if (!empty($options['cache']) && is_string($options['cache'])) {
$bootstrap = $this->getBootstrap();
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper && $bootstrap->hasPluginResource('CacheManager')) {
$cacheManager = $bootstrap->bootstrap('CacheManager')->getResource('CacheManager');
if (null !== $cacheManager && $cacheManager->hasCache($options['cache'])) {
$options['cache'] = $cacheManager->getCache($options['cache']);
}
}
}
$key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY;
unset($options['registry_key']);
if (Zend_Registry::isRegistered($key)) {
$translate = Zend_Registry::get($key);
if (!$translate instanceof Zend_Translate) {
require_once LIB_DIR . '/Zend/Application/Resource/Exception.php';
throw new Zend_Application_Resource_Exception($key . ' already registered in registry but is ' . 'no instance of Zend_Translate');
}
$translate->addTranslation($options);
$this->_translate = $translate;
} else {
$this->_translate = new Zend_Translate($options);
Zend_Registry::set($key, $this->_translate);
}
}
return $this->_translate;
}
示例4: getInstance
/**
* Returns a singelton logger instance.
*
* @return Zend_Log
*/
public static function getInstance()
{
if (self::$_instance === null) {
$config = Zend_Registry::get('config');
self::$_instance = Zend_Log::factory(array(array('writerName' => 'Stream', 'writerParams' => array('stream' => 'php://output'), 'filterName' => 'Priority', 'filterParams' => array('priority' => constant('Zend_Log::' . $config->log->level)))));
}
return self::$_instance;
}
示例5: getLog
public function getLog()
{
if (null === $this->_log) {
$options = $this->getOptions();
$log = Zend_Log::factory($options);
$this->setLog($log);
}
return $this->_log;
}
示例6: factory
/**
* Shortcut to fetching a configured logger instance
*
* @param array|Zend_Config $config Array or instance of Zend_Config
* @return Zend_Log
*/
public static function factory($config = array())
{
if (is_string($config)) {
// Assume $config is a filename
$filename = $config;
$config = array('timestampFormat' => 'Y-m-d', array('writerName' => 'Stream', 'writerParams' => array('stream' => self::_getLoggingDirectory() . DIRECTORY_SEPARATOR . $filename)));
}
return parent::factory($config);
}
示例7: buildLog
/**
* Build a log object used internally by parent class
*
* @return void
*/
protected function buildLog()
{
if (isset($this->_options['log'])) {
if (is_array($this->_options['log'])) {
$this->_options['log'] = Zend_Log::factory($this->_options['log']);
} else {
unset($this->_options['log']);
}
}
}
示例8: testFactory
public function testFactory()
{
$cfg = array('log' => array('memory' => array('writerName' => "Mock", 'filterName' => "Priority", 'filterParams' => array('priority' => "Zend_Log::CRIT", 'operator' => "<="))));
$logger = Zend_Log::factory($cfg['log']);
$this->assertTrue($logger instanceof Zend_Log);
try {
$logger = Zend_Log::factory(array('Null' => array('writerName' => 'Mock', 'filterName' => 'Priority', 'filterParams' => array())));
} catch (Exception $e) {
$this->assertType('Zend_Log_Exception', $e);
$this->assertRegExp('/must be an integer/', $e->getMessage());
}
}
示例9: getLogs
public function getLogs()
{
if (null === $this->_logs) {
$options = $this->getOptions();
foreach ($options as $key => $opt) {
// Detect if we are only giving one writer
if (0 === strpos(key($opt), 'writerN')) {
$opt = array($key => $opt);
}
$log = Zend_Log::factory($opt);
$this->addLog($key, $log);
}
}
return $this->_logs;
}
示例10: getLog
public function getLog()
{
if (null === $this->_log) {
$options = $this->getOptions();
foreach ($options as $key => $writer) {
if ($writer['writerName'] == "Db" && is_array($writer['writerParams']['db'])) {
$params = $writer['writerParams']['db'];
$options[$key]['writerParams']['db'] = Zend_Db::factory($params['adapter'], $params);
}
}
$log = Zend_Log::factory($options);
$log->setTimestampFormat('Y-m-d H:i:s');
$this->setLog($log);
}
return $this->_log;
}
示例11: _initLog
protected function _initLog()
{
// Sandra SSSSS este função tem que ficar comentada em produção - para não ficar criando arquivos de log desnecessariamente
$options = $this->getOption('resources');
$partitionConfig = $this->getOption('log');
$logOptions = $options['log'];
$baseFilename = $logOptions['stream']['writerParams']['stream'];
if ($partitionConfig['partitionStrategy'] == 'context') {
$baseFilename = $partitionConfig['path'] . '/' . APPLICATION_ENV;
}
$logFilename = $baseFilename . '_' . date('Y_W');
//semanalmente
$logOptions['stream']['writerParams']['stream'] = $logFilename;
$logger = Zend_Log::factory($logOptions);
Zend_Registry::set('logger', $logger);
return $logger;
}
示例12: _initLog
/**
* 初始化Log
*
* @return Zend_Log
*/
public function _initLog()
{
$configs = $this->_options['resources']['log'];
foreach ($configs as $key => &$config) {
$params =& $config['writerParams'];
if (strtolower($key) == 'db') {
if (!empty($params['db']) && !empty($params['table'])) {
$params['db'] = $this->getResource('multidb')->getDb($params['db']);
$params['columnMap'] = array('SEVERITY' => 'priority', 'ORIGIN' => 'from', 'DATA' => 'data', 'MESSAGE' => 'message');
} else {
unset($configs[$key]);
}
}
}
$logger = Zend_Log::factory($configs);
return $logger;
}
示例13: getLogger
public static function getLogger()
{
if (Zend_Registry::isRegistered(self::LOGGER)) {
return Zend_Registry::get(self::LOGGER);
}
$config = new Zend_Config_Ini(ROOT_PATH . '/config/log.ini');
$config = $config->toArray();
$date = new Zend_Date();
$part = "YYYY-MM-dd";
$fileName = $config[0]['writerParams']['stream'];
$ext = substr($fileName, -4);
$fileName = substr($fileName, 0, -4);
$fileName = $fileName . "_" . $date->get($part) . $ext;
$config[0]['writerParams']['stream'] = $fileName;
$logger = Zend_Log::factory($config);
Zend_Registry::set(self::LOGGER, $logger);
return $logger;
}
示例14: getCacheManager
/**
* Retrieve Zend_Cache_Manager instance
*
* @return Zend_Cache_Manager
*/
public function getCacheManager()
{
if (null === $this->_manager) {
$this->_manager = new Zend_Cache_Manager();
$options = $this->getOptions();
foreach ($options as $key => $value) {
// Logger
if (isset($value['frontend']['options']['logger'])) {
$logger = $value['frontend']['options']['logger'];
if (is_array($logger)) {
$value['frontend']['options']['logger'] = Zend_Log::factory($logger);
}
}
// Cache templates
if ($this->_manager->hasCacheTemplate($key)) {
$this->_manager->setTemplateOptions($key, $value);
} else {
$this->_manager->setCacheTemplate($key, $value);
}
}
}
return $this->_manager;
}
示例15: __construct
/**
*
* @param ZtChart_Model_Monitor_Console $console
* @param array $config
*/
public function __construct(ZtChart_Model_Monitor_Console $console, $config = array())
{
$this->_console = $console;
foreach ($config as $name => $value) {
$method = 'set' . ucfirst($name);
if (method_exists($this, $method)) {
$method($value);
}
}
if (null === $this->_db) {
$this->_db = self::$_defaultDb;
}
if (null === $this->_logger) {
$this->_logger = Zend_Log::factory(array(array('writerName' => 'Stream', 'writerParams' => array('stream' => 'php://stderr'), 'filterName' => 'Priority', 'filterParams' => array('priority' => Zend_Log::ERR, 'operator' => '<=')), array('writerName' => 'Stream', 'writerParams' => array('stream' => 'php://stdout'), 'filterName' => 'Priority', 'filterParams' => array('priority' => Zend_Log::INFO))));
}
}