本文整理汇总了PHP中Zend_Log类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Log类的具体用法?PHP Zend_Log怎么用?PHP Zend_Log使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Log类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: addItem
public static function addItem($message, $error = false)
{
global $s1b;
if (self::getConfig()->getTracesEnabled() || self::getConfig()->getLogsEnabled()) {
if (!strlen(trim($message))) {
throw new \Exception('Cannot insert empty trace.');
}
// Ecriture du message dans le tableau des items en sessions si traces activées
if (self::getConfig()->getTracesEnabled()) {
self::initItems();
self::$items[] = $message;
}
// Ecriture du log si activé
if (self::getConfig()->getLogsEnabled()) {
// vérification de l'existence du fichier et création si non existant
$now = new \DateTime();
$logFilePath = self::getContext()->getBaseDirectory() . sprintf("/var/log/%s-log.txt", $now->format("Ymd"));
if (!file_exists($logFilePath)) {
$file = fopen($logFilePath, "w");
fclose($file);
}
// ecriture du log dans le fichier
$writer = new \Zend_Log_Writer_Stream($logFilePath);
$logger = new \Zend_Log($writer);
if ($error) {
$logger->err($message);
} else {
$logger->info($message);
}
$logger = null;
}
}
}
示例3: _initFirebugLog
/**
* Inicializa o logger do Firebug
*/
protected function _initFirebugLog()
{
$logger = new Zend_Log();
$writerFirebug = new Zend_Log_Writer_Firebug();
$logger->addWriter($writerFirebug);
Zend_Registry::set('logger', $logger);
}
示例4: getLogger
public static function getLogger(Zend_Config $config = null)
{
$logger = new Zend_Log();
$hasWriters = false;
if ($config !== null && $config->writers !== null) {
foreach ($config->writers as $writerConfig) {
$writer = self::getWriter($writerConfig);
if ($writer !== null) {
$logger->addWriter($writer);
$hasWriters = true;
}
}
}
if (!$hasWriters) {
$logger->addWriter(new Zend_Log_Writer_Null());
}
// to turn off logging without making the logger throw exceptions
if ($config !== null && $config->eventItems !== null) {
foreach ($config->eventItems as $eventItemName => $eventItemClass) {
$eventItemClass = (string) $eventItemClass;
if (class_exists($eventItemClass)) {
$logger->setEventItem($eventItemName, new $eventItemClass());
}
}
}
return $logger;
}
示例5: __construct
private function __construct()
{
// setup file error logging
$file_writer = new Logger_Errorlog();
if (Config::get_optional("DEBUG_LOG") == false) {
$file_writer->addFilter(Zend_Log::INFO);
}
$log = new Zend_Log();
$log->addWriter($file_writer);
// setup email error logging
if (Config::get_optional("log_to_email") == true) {
$mail = new Zend_Mail();
$mail->setFrom(Config::get_mandatory('log_email_from'));
$mail->addTo(Config::get_mandatory('log_email_to'));
// setup email template
$layout = new Zend_Layout();
$layout->setLayoutPath(DOCUMENT_ROOT . Config::get_mandatory("log_email_template"));
$layout->setLayout('error-logger');
$layout_formatter = new Zend_Log_Formatter_Simple('<li>.' . Zend_Log_Formatter_Simple::DEFAULT_FORMAT . '</li>');
// Use default HTML layout.
$email_writer = new Zend_Log_Writer_Mail($mail, $layout);
$email_writer->setLayoutFormatter($layout_formatter);
$email_writer->setSubjectPrependText(Config::get_mandatory('log_email_subject_prepend'));
$email_writer->addFilter(Zend_Log::ERR);
$log->addWriter($email_writer);
}
self::$logger = $log;
}
示例6: _initLogs
protected function _initLogs()
{
$logger = new Zend_Log();
$fireBugWriter = new Zend_Log_Writer_Firebug();
$logger->addWriter($fireBugWriter);
Zend_Registry::set('logger', $logger);
}
示例7: _initLogger
/**
* Init for the logger.
*
*/
protected function _initLogger()
{
$logger = new Zend_Log();
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../log/' . $this->_config->log->file);
$logger->addWriter($writer);
Zend_Registry::set('log', $logger);
}
示例8: preDispatch
/**
* (non-PHPdoc)
* @see Zend_Controller_Plugin_Abstract::preDispatch()
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
try {
$layout = Zend_Layout::getMvcInstance()->getLayout();
$boostrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$userAgent = $boostrap->getResource('useragent');
$device = $userAgent->getDevice();
$mdlSkin = new System_Model_Skin();
$skin = $mdlSkin->getSkinSelected();
$skinName = is_null($skin) ? 'default' : strtolower($skin->name);
$vr = Zend_Controller_Action_HelperBroker::getStaticHelper('Layout');
$view = $vr->getView();
$skinData = new Zend_Config_Xml('./skins/' . $skinName . '/skin.xml');
# css files
$stylesheet = (int) $device->getFeature('is_desktop') == 1 ? $skinData->files->stylesheet : $skinData->files->stylesheetMobile;
$view->headLink()->prependStylesheet($view->baseUrl() . '/skins/' . $skinName . '/css/' . $stylesheet);
$view->headLink()->headLink(array('rel' => 'favicon', 'href' => $view->baseUrl() . '/skins/' . $skinName . '/favicon.ico'), 'PREPEND');
Zend_Registry::set('skin', $skinName);
# javascript files
$jsfiles = $skinData->files->js->toArray();
foreach ($jsfiles as $js) {
$view->headScript()->prependFile($view->baseUrl() . '/skins/' . $skinName . '/js/' . $js);
}
} catch (Exception $e) {
try {
$writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'plugins.log');
$logger = new Zend_Log($writer);
$logger->log($e->getMessage(), Zend_Log::ERR);
} catch (Exception $e) {
}
}
}
示例9: 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']);
}
示例10: 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) {
}
}
}
示例11: getInstance
/**
* This method will instantiate the object, configure it and return it
*
* @return Zend_Cache_Manager
*/
public static function getInstance()
{
$path = realpath(APPLICATION_PATH . '/../logs/' . CURRENT_MODULE . '/mailer.log');
$logger = new Zend_Log();
$logger->addWriter(new Zend_Log_Writer_Stream($path));
return $logger;
}
示例12: preDispatch
/**
* Check the application.ini file for security settings.
* If the url requires being secured, rebuild a secure url
* and redirect.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
* @author Travis Boudreaux
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
try {
$shouldSecureUrl = false;
$options = Zend_Registry::getInstance()->get('options');
// ar_dump($options['ssl'][$request->module][$request->controller][$request->action]['require_ssl']);
// ie();
// f (APPLICATION_ENV == ENV_PRODUCTION ) {
// check configuration file for one of three require_ssl directives
// secure an entire module with modules.module_name.require_ssl =
// true
// secure an entire controller with
// modules.module_name.controller_name.require_ssl = true
// secure an action with
// modules.module_name.controller_name.action_name.require_ssl =
// true
if (@$options['ssl'][$request->module]['require_ssl'] || @$options['ssl'][$request->module][$request->controller]['require_ssl'] || @$options['ssl'][$request->module][$request->controller][$request->action]['require_ssl']) {
$shouldSecureUrl = true;
}
if ($shouldSecureUrl) {
$this->_secureUrl($request, true);
} else {
$this->_secureUrl($request, false);
}
//
} catch (Exception $e) {
try {
$writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'plugins.log');
$logger = new Zend_Log($writer);
$logger->log($e->getMessage(), Zend_Log::ERR);
} catch (Exception $e) {
}
}
}
示例13: preDispatch
/**
* PreDispatch method for ACL Plugin. It checks if current user has privileges for resources requested
* @see Zend_Controller_Plugin_Abstract::preDispatch()
* @param Zend_Controller_Request_Abstract $request
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
try {
$module = strtolower($request->getParam('module'));
$controller = strtolower($request->getParam('controller'));
$action = strtolower($request->getParam('action'));
$resource = $module . ":" . $controller;
$acl = Zend_Registry::get('ZendACL');
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
$roleID = $auth->hasIdentity() ? $auth->getIdentity()->role_id : 3;
#var_dump($acl->isAllowed( $roleID, $resource, $action), $roleID, $resource, $action);
#Zend_Debug::dump($module, $controller, $action, $roleID, $acl);
#die();
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
if ($acl->isAllowed($roleID, $resource, $action) != true) {
$redirector->gotoUrl('logout')->redirectAndExit();
} else {
return;
}
} catch (Exception $e) {
try {
$writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'plugins.log');
$logger = new Zend_Log($writer);
$logger->log($e->getMessage(), Zend_Log::ERR);
} catch (Exception $e) {
}
}
}
示例14: startLog
protected function startLog()
{
$writer = new \Zend_Log_Writer_Stream('php://stdout');
$logger = new \Zend_Log($writer);
$logger->addPriority("sql", 8);
$this->config->log = $logger;
}
示例15: errorAction
public function errorAction()
{
$http_accept = $_SERVER['HTTP_ACCEPT'];
$this->_redirecUnknownImage($http_accept);
$errors = $this->_getParam('error_handler');
$msg = $errors->exception->getMessage();
$backTrace = $errors->exception->getTraceAsString();
$this->_handleMessage($errors);
$this->_helper->viewRenderer->setViewScriptPathSpec('error/' . $this->getResponse()->getHttpResponseCode() . '.:suffix');
$this->view->exception = $errors->exception;
$this->view->request = $errors->request;
$this->view->ui = 1;
$logPath = realpath(APPLICATION_PATH . '/../log') . "/error";
if (!is_dir($logPath)) {
mkdir($logPath, 755, TRUE);
}
$log = new Zend_Log(new Zend_Log_Writer_Stream($logPath . "/" . date("Ymd") . "_applicationException.log"));
$params1 = $this->_request->getParams();
unset($params1["error_handler"]);
$params = Zend_Json::encode($params1);
$messages = array($msg, $backTrace, $params, "HTTP_ACCEPT: " . $http_accept, "");
$log->err(implode(self::LOG_EOL, $messages));
try {
self::$_dispatcher->notify(new sfEvent($this, 'error.log', array('message' => array($msg, $backTrace), 'priority' => 3)));
return;
} catch (Exception $e) {
echo $e->getMessage();
}
}