/** * @return Zend_Log */ public function init() { $bootstrap = $this->getBootstrap(); $bootstrap->bootstrap('Config'); $config = $bootstrap->getResource('Config'); if (!$config->log->errors && !$config->log->sql) { return; } $logFile = LOGS_DIR . '/' . 'errors.log'; if (!is_writable($logFile)) { throw new RuntimeException('Error log file cannot be written to. Please give this file read/write permissions for the web server.'); } $writer = new Zend_Log_Writer_Stream($logFile); $logger = new Zend_Log($writer); if (isset($config->log->priority)) { $priority = $config->log->priority; if (defined($priority)) { $writer->addFilter(constant($priority)); } } if (!empty($config->debug->email)) { $bootstrap->bootstrap('Mail'); $this->_addMailWriter($logger, (string) $config->debug->email, $config->debug->emailLogPriority); } return $logger; }
/** * Writer untuk log message error * Log message error akan dituliskan ke dalam file error.log */ protected function _errorWriter() { $log = ROOT_DIR . '/data/log/error.log'; $stream = fopen($log, 'a', false); if (!$stream) { throw new Exception('Failed to open _error stream'); } $writer = new Zend_Log_Writer_Stream($stream); $writer->addFilter(new Zend_Log_Filter_Priority(Zend_Log::ERR)); $writer->setFormatter($this->_formatter); return $writer; }
private function __construct() { $config = Zend_Registry::get('config'); /* Set up a stream logger to a file. */ if ($config->logger->filename == null) { $writer = new Zend_Log_Writer_Stream('php://output'); } else { $writer = new Zend_Log_Writer_Stream($config->logger->filename); } switch ($config->logger->level) { case "FATAL": $writer->addFilter(Zend_Log::CRIT); break; case "ERROR": $writer->addFilter(Zend_Log::ERR); break; case "WARN": $writer->addFilter(Zend_Log::WARN); break; case "INFO": $writer->addFilter(Zend_Log::INFO); break; case "DEBUG": $writer->addFilter(Zend_Log::DEBUG); break; default: $writer->addFilter(Zend_Log::WARN); break; } $this->_zLogger = new Zend_Log($writer); }
public function testFilterOnSpecificWriter() { $log2 = fopen('php://memory', 'w'); $writer2 = new Zend_Log_Writer_Stream($log2); $writer2->addFilter(Zend_Log::ERR); $this->logger->addWriter($writer2); $this->logger->warn($warn = 'warn-message'); $this->logger->err($err = 'err-message'); rewind($this->log); $logdata = stream_get_contents($this->log); $this->assertContains($warn, $logdata); $this->assertContains($err, $logdata); rewind($log2); $logdata = stream_get_contents($log2); $this->assertContains($err, $logdata); $this->assertNotContains($warn, $logdata); }
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; }
/** * (non-PHPdoc) * @see Syncope/Syncope_TestCase::setUp() */ protected function setUp() { Syncope_Registry::setDatabase(getTestDatabase()); Syncope_Registry::setTransactionManager(Syncope_TransactionManager::getInstance()); Syncope_Registry::getTransactionManager()->startTransaction(Syncope_Registry::getDatabase()); #$writer = new Zend_Log_Writer_Null(); $writer = new Zend_Log_Writer_Stream('php://output'); $writer->addFilter(new Zend_Log_Filter_Priority($this->_logPriority)); $logger = new Zend_Log($writer); $this->_deviceBackend = new Syncope_Backend_Device(Syncope_Registry::getDatabase()); $this->_folderBackend = new Syncope_Backend_Folder(Syncope_Registry::getDatabase()); $this->_syncStateBackend = new Syncope_Backend_SyncState(Syncope_Registry::getDatabase()); $this->_contentStateBackend = new Syncope_Backend_Content(Syncope_Registry::getDatabase()); $this->_device = $this->_deviceBackend->create(Syncope_Backend_DeviceTests::getTestDevice()); Syncope_Registry::set('deviceBackend', $this->_deviceBackend); Syncope_Registry::set('folderStateBackend', $this->_folderBackend); Syncope_Registry::set('syncStateBackend', $this->_syncStateBackend); Syncope_Registry::set('contentStateBackend', $this->_contentStateBackend); Syncope_Registry::set('loggerBackend', $logger); Syncope_Registry::setContactsDataClass('Syncope_Data_Contacts'); Syncope_Registry::setCalendarDataClass('Syncope_Data_Calendar'); Syncope_Registry::setEmailDataClass('Syncope_Data_Email'); Syncope_Registry::setTasksDataClass('Syncope_Data_Tasks'); }
/** * Accumulate log messages, but also append them to a running log file for easy viewing. */ public static function log($msg, $before = null) { static $flushed = false; if ($before) { self::$_log = "{$msg}\n" . self::$_log; } else { self::$_log .= "{$msg}\n"; } $registry = Zend_Registry::getInstance(); // performance is not an issue for this demo, so just sync to disk everytime if (isset($registry['config'])) { if ($flushed) { file_put_contents($registry['config']->log, "{$msg}\n", FILE_APPEND); } else { file_put_contents($registry['config']->log, self::$_log); $flushed = true; ///////////////////////////// // ==> SECTION: log <== require 'Zend/Log.php'; require 'Zend/Log/Formatter/Simple.php'; require 'Zend/Log/Writer/Stream.php'; $filename = $registry['config']->log . '.error'; $errorLogStream = @fopen($filename, 'wb', false); if ($errorLogStream === false) { throw new ZFDemo_Exception("CRITICAL: Can not open log file '{$filename}' for writing", 500); } $filename = $registry['config']->log . '.verbose'; $verboseLogStream = @fopen($filename, 'wb', false); if ($verboseLogStream === false) { throw new ZFDemo_Exception("CRITICAL: Can not open log file '{$filename}' for writing", 500); } // create a custom formatter for our log writers, so that we can include the custom user %id% field $formatter = new Zend_Log_Formatter_Simple('%timestamp% %priorityName% (%priority%) %id%: %message%' . PHP_EOL); // create a log writer for errors, using the previously opened stream $errorWriter = new Zend_Log_Writer_Stream($errorLogStream); $errorWriter->setFormatter($formatter); $filter = new Zend_Log_Filter_Priority(Zend_Log::ERR); $errorWriter->addFilter($filter); // log messages lower than priority ERR are ignored by this writer // create a log writer for all messages, using the previously opened stream $verboseWriter = new Zend_Log_Writer_Stream($verboseLogStream); $verboseWriter->setFormatter($formatter); // all log messages are logged by this writer // finally, create a logger and attach the two log writers to the logger self::$_logger = new Zend_Log($errorWriter); self::$_logger->addWriter($verboseWriter); self::$_logger->pause = false; } } self::$_messages[] = $msg; if (self::$_logger && !self::$_logger->pause) { while (count(self::$_messages)) { $msg = array_shift(self::$_messages); // Each log event has: timestamp, message, priority, and priorityName // Now we add an additional datum, the authentication id (if any) of the current user. if (isset($registry['authenticationId']) && isset($registry['authenticationId']['username'])) { $id = $registry['authenticationId']['username'] . '.' . $registry['authenticationId']['realm']; } else { $id = '-'; } self::$_logger->setEventItem('id', $id); $priority = substr($msg, 0, $pos = strpos($msg, ' ')); if (isset($priorities[$priority])) { $priority = $priorities[$priority]; $msg = substr($msg, $pos + 1); } else { $priority = 7; // default to DEBUG priority } self::$_logger->log($msg, $priority); } } }
die; } if (!isset($_SERVER['argv'][1]) || !in_array($_SERVER['argv'][1], array('install'))) { die('Usage: php lib/profilelib/shell.php command [option] Where command [option] can be: install profile_name [repository=profiles.tiki.org] '); } if (!file_exists('db/local.php')) { die("Tiki is not installed yet.\n"); } require_once 'tiki-setup.php'; include_once 'lib/core/Zend/Log/Writer/Syslog.php'; $log_level = Zend_Log::INFO; $writer = new Zend_Log_Writer_Stream('php://output'); $writer->addFilter((int) $log_level); $logger = new Zend_Log($writer); $logger->debug('Running search shell utility'); require_once 'lib/profilelib/profilelib.php'; require_once 'lib/profilelib/installlib.php'; if ($_SERVER['argv'][1] === 'install') { $args = $_SERVER['argv']; $script = array_shift($args); $command = array_shift($args); $profile = array_shift($args); $repository = array_shift($args); if (!$repository) { $repository = 'profiles.tiki.org'; } if (!$profile) { $logger->err('Profile not specified.');
* * Example server file * * @package doc * @license http://www.tine20.org/licenses/lgpl.html LGPL Version 3 * @copyright Copyright (c) 2012-2012 Metaways Infosystems GmbH (http://www.metaways.de) * @author Lars Kneschke <*****@*****.**> */ if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="Syncroton"'); header('HTTP/1.0 401 Unauthorized'); echo 'Please authenticate!'; exit; } // http://localhost/Microsoft-Server-ActiveSync $paths = array(realpath(dirname(__FILE__) . '/../forbidden/zend1/library/'), realpath(dirname(__FILE__)), realpath(dirname(__FILE__) . '/lib'), get_include_path()); set_include_path(implode(PATH_SEPARATOR, $paths)); require_once 'Zend\\Loader\\Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->setFallbackAutoloader(true); $db = Zend_Db::factory('PDO_MYSQL', array('host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'dbname' => 'syncro')); Syncroton_Registry::setDatabase($db); $writer = new Zend_Log_Writer_Stream(dirname(__FILE__) . '\\syncroton.log'); $writer->addFilter(new Zend_Log_Filter_Priority(Zend_Log::DEBUG)); Syncroton_Registry::set('loggerBackend', new Zend_Log($writer)); Syncroton_Registry::setContactsDataClass('Syncroton_Data_Contacts'); Syncroton_Registry::setCalendarDataClass('Syncroton_Data_Calendar'); Syncroton_Registry::setTasksDataClass('Syncroton_Data_Tasks'); #Syncroton_Registry::setEmailDataClass('Syncroton_Data_Email'); $server = new Syncroton_Server($_SERVER['PHP_AUTH_USER']); $server->handle();
/** * Initialize the logger * * @return \Gems_Log */ protected function _initLogger() { $this->bootstrap('project'); // Make sure the project object is available $logger = \Gems_Log::getLogger(); $logPath = GEMS_ROOT_DIR . '/var/logs'; try { $writer = new \Zend_Log_Writer_Stream($logPath . '/errors.log'); } catch (Exception $exc) { try { // Try to solve the problem, otherwise fail heroically \MUtil_File::ensureDir($logPath); $writer = new \Zend_Log_Writer_Stream($logPath . '/errors.log'); } catch (Exception $exc) { $this->bootstrap(array('locale', 'translate')); die(str_replace(GEMS_ROOT_DIR . '/', '', sprintf($this->translateAdapter->_('Path %s not writable') . "\n%s\n", $logPath, $exc->getMessage()))); } } $filter = new \Zend_Log_Filter_Priority($this->project->getLogLevel()); $writer->addFilter($filter); $logger->addWriter($writer); // OPTIONAL STARTY OF FIREBUG LOGGING. if ($this->_startFirebird) { $logger->addWriter(new \Zend_Log_Writer_Firebug()); //We do not add the logLevel here, as the firebug window is intended for use by //developers only and it is only written to the active users' own screen. } \Zend_Registry::set('logger', $logger); return $logger; }
/** * add new log writer defined by a config object/array * * @param Tinebase_Config_Struct|Zend_Config|array $loggerConfig * * @throws Tinebase_Exception_NotFound */ public function addWriterByConfig($loggerConfig) { $loggerConfig = $loggerConfig instanceof Tinebase_Config_Struct || $loggerConfig instanceof Zend_Config ? $loggerConfig : new Tinebase_Config_Struct($loggerConfig); if (empty($loggerConfig->filename)) { throw new Tinebase_Exception_NotFound('filename missing in logger config'); } $filename = $loggerConfig->filename; $writer = new Zend_Log_Writer_Stream($filename); $writer->setFormatter($this->getFormatter()); $priority = $loggerConfig->priority ? (int) $loggerConfig->priority : Zend_Log::EMERG; $filter = new Zend_Log_Filter_Priority($priority); $writer->addFilter($filter); // add more filters here if (isset($loggerConfig->filter->user)) { $writer->addFilter(new Tinebase_Log_Filter_User($loggerConfig->filter->user)); } if (isset($loggerConfig->filter->message)) { $writer->addFilter(new Zend_Log_Filter_Message($loggerConfig->filter->message)); } $this->addWriter($writer); }
// that corresponds to the APP's Environment $configuration = new Zend_Config_Ini(CONFIG_FILE, APPLICATION_ENVIRONMENT, true); $arsConfig = new Zend_Config_Ini(APPLICATION_PATH . '/modules/ars/config/ars.ini', APPLICATION_ENVIRONMENT); if (file_exists(LOCAL_CONFIG_FILE) && is_readable(LOCAL_CONFIG_FILE)) { $localConfig = new Zend_Config_Ini(LOCAL_CONFIG_FILE, APPLICATION_ENVIRONMENT); $configuration->merge($localConfig); } // LOGGER $logfile = APPLICATION_PATH . "/" . $configuration->log->path; if (is_file($logfile) && !is_writeable($logfile)) { die("Unable to write to log file " . $logfile); } $writer = new Zend_Log_Writer_Stream($logfile); $writer->setFormatter(new Zend_Log_Formatter_Simple('%timestamp% %priorityName% %request% %remote%: %message%' . "\n")); $filter = new Zend_Log_Filter_Priority((int) $configuration->log->level); $writer->addFilter($filter); $logger = new Zend_Log($writer); $logger->setEventItem('pid', getmypid()); $logger->setEventItem('request', $_SERVER['REQUEST_URI']); $logger->setEventItem('remote', $_SERVER['REMOTE_ADDR']); // TRANSLATIONS $locale = new Zend_Locale(); Zend_Registry::set('Zend_Locale', $locale); // default language when requested language is not available $defaultlanguage = 'en'; define('DEFAULT_LANGUAGE', 'en'); $translate = new Zend_Translate('csv', APPLICATION_PATH . '/languages/', null, array('scan' => Zend_Translate::LOCALE_FILENAME)); $translate->setOptions(array('log' => $logger, 'logUntranslated' => true)); if (!$translate->isAvailable($locale->getLanguage())) { // not available languages are rerouted to another language $translate->setLocale(DEFAULT_LANGUAGE);
protected function _initLogger() { $config = $this->getOption('email'); $logger = new Zend_Log(); // register our custom error handler App_Error_Handler::register(); $writer_filesys = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../data/log/zf.iati.log'); $writer_filesys->addFilter(Zend_Log::WARN); $logger->addWriter($writer_filesys); if (APPLICATION_ENV == 'production') { $email = new Zend_Mail(); $email->setFrom($config['fromAddress'])->addTo($config['errLogging']); $writer_email = new Zend_Log_Writer_Mail($email); $writer_email->setSubjectPrependText('Urgent: IATI Server Error!'); // only email warning level "errors" or higher $writer_email->addFilter(Zend_Log::WARN); $logger->addWriter($writer_email); } Zend_Registry::set('logger', $logger); return $logger; }
/** * add log writer for php://output * * @param integer $priority */ protected function _addOutputLogWriter($priority = 5) { $writer = new Zend_Log_Writer_Stream('php://output'); $writer->addFilter(new Zend_Log_Filter_Priority($priority)); Tinebase_Core::getLogger()->addWriter($writer); }
/** * Zend_Log setup * @param array $config */ function _initLogger($config = '') { if (!empty($config['logger'])) { $conf = $config['logger']; $logger = new Zend_Log(); if (!empty($conf['writer'])) { if (!empty($conf['mode'])) { $mode = $conf['mode']; } elseif (LOCATION == 'stable') { $mode = 'a'; } else { $mode = 'w'; } $writer = new Zend_Log_Writer_Stream($conf['writer'], $mode); #if (!ZX_DEBUG) { $priority = !empty($conf['priority']) ? $conf['priority'] : Zend_Log::INFO; $filter = new Zend_Log_Filter_Priority($priority); $writer->addFilter($filter); #} $logger->addWriter($writer); // we care about log length :) } if (!empty($conf['firebug'])) { $logger->addWriter(new Zend_Log_Writer_Firebug()); } Zend_Registry::set('logger', $logger); return TRUE; } return FALSE; }
private function createSystemStream($path = null, $priority = null) { if ($priority == null) { $priority = $this->_defaultPriority; } $logger = new Logger_Application_ZendLogWrapper(); $writer = null; if ($path == null) { $writer = new Zend_Log_Writer_Null(); $logger->addWriter($writer); } else { self::$_systemLogPath = $path; $writer = new Zend_Log_Writer_Stream($path); $writer->addFilter(new Zend_Log_Filter_Priority($priority)); $logger->addWriter($writer); } if (self::$_errorLogPath !== null) { $writer = new Zend_Log_Writer_Stream(self::$_errorLogPath); $writer->addFilter(new Zend_Log_Filter_Priority(Zend_Log::ERR)); $logger->addWriter($writer); } return $logger; }
protected function addFileWriterLogger(Zend_Log $logger, $config) { if (!(isset($config->active) && $config->active == 1)) { return; } if (!@touch($config->logfile)) { // do not log if we can't write the file return; } $fileLogWriter = new Zend_Log_Writer_Stream($config->logfile); if (isset($config->format)) { $fileLogWriter->setFormatter(new Zend_Log_Formatter_Simple($config->format . PHP_EOL)); } if (isset($config->level)) { $fileLogWriter->addFilter((int) $config->level); } $logger->addWriter($fileLogWriter); }
/** * repair dangling attendee records (no displaycontainer_id) * * @see https://forge.tine20.org/mantisbt/view.php?id=8172 */ public function repairDanglingDisplaycontainerEvents() { $writer = new Zend_Log_Writer_Stream('php://output'); $writer->addFilter(new Zend_Log_Filter_Priority(5)); Tinebase_Core::getLogger()->addWriter($writer); $be = new Calendar_Backend_Sql(); $be->repairDanglingDisplaycontainerEvents(); }
protected function _initLogger() { $log = Snep_Logger::getInstance(); $config = Snep_Config::getConfig(); $writer = new Zend_Log_Writer_Stream($config->system->path->log . '/ui.log'); // Filtramos a 'sujeira' dos logs se não estamos em debug mode. if (!$config->system->debug) { $filter = new Zend_Log_Filter_Priority(Zend_Log::WARN); $writer->addFilter($filter); } $log->addWriter($writer); }