Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 /**
  * Initialize Logging
  *
  */
 protected function _initLogging()
 {
     $this->bootstrap('log');
     Zend_Registry::set('log', $log = $this->getResource('log'));
     $mail = new Zend_Mail();
     $config = Zend_Registry::get('config');
     $mail->addTo($config->core->debugMailTo);
     $layout = new Zend_Layout();
     $layout->setLayout('errormail');
     $writer = new Zend_Log_Writer_Mail($mail, $layout);
     $writer->setSubjectPrependText('CORE Error');
     $writer->addFilter(Zend_Log::CRIT);
     #$log->addWriter($writer);
 }
Exemplo n.º 3
0
 /**
  * Set up debugging emails.
  *
  * @param Zend_Log $log
  * @param string $toEmail Email address of debug message recipient.
  */
 private function _addMailWriter(Zend_Log $log, $toEmail, $filter = null)
 {
     $mailer = new Zend_Mail();
     $mailer->addTo($toEmail);
     $mailer->setFrom(get_option('administrator_email'));
     $logWriter = new Zend_Log_Writer_Mail($mailer);
     $logWriter->setSubjectPrependText('[' . get_option('site_title') . ']');
     if ($filter) {
         // Zend_Log::ERR, e.g.
         if (defined($filter)) {
             $filter = constant($filter);
         }
         $logWriter->addFilter($filter);
     }
     $log->addWriter($logWriter);
 }
Exemplo n.º 4
0
 /**
  * Sends mail to recipient(s) if log entries are present.  Note that both
  * plaintext and HTML portions of email are handled here.
  *
  * @return void
  */
 public function shutdown()
 {
     parent::shutdown();
     unset($this->_tempLogger);
     if (is_file($this->_tempfile)) {
         unlink($this->_tempfile);
     }
 }
Exemplo n.º 5
0
 /**
  * Send the log mails
  *
  * @param array $event Event data
  */
 public function _write($event)
 {
     //Lazy intatiation of underlying mailer
     if ($this->_mail === null) {
         $this->_mail = $this->getMail();
     }
     parent::_write($event);
 }
Exemplo n.º 6
0
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');

        if (!$errors) {
            $this->view->message = 'You have reached the error page';
            return;
        }

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:

                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Page not found';
                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = 'Application error';
                break;
        }

        $mail = new Zend_Mail();
        $mail->setFrom('*****@*****.**')
            ->addTo('*****@*****.**');

        $writer = new Zend_Log_Writer_Mail($mail);
        $writer->setSubjectPrependText('Errors from facebook');

        $log = new Zend_Log();
        $log->addWriter($writer);

        $message = "Message: {$errors->exception->getMessage()} \nStack trace: {$errors->exception->getTraceAsString()}";
        $log->crit($message);

        // conditionally display exceptions
        if ($this->getInvokeArg('displayExceptions') == true) {
            $this->view->exception = $errors->exception;
        }

        $this->view->request   = $errors->request;
    }
Exemplo n.º 7
0
 /**
  * 
  * constructs the helper
  */
 protected function __construct()
 {
     if (APPLICATION_ENV != 'production') {
         $writer = new Zend_Log_Writer_Firebug();
         $writer->setDefaultPriorityStyle('EXCEPTION');
     } else {
         $mailConfig = Zend_Registry::get('emailSettings');
         if ($mtconf->sendmail) {
             $mtconf = array('auth' => 'login', 'username' => $mailConfig->smtp->user, 'password' => $mailConfig->smtp->password, 'port' => $mailConfig->smtp->port);
             if ($mailConfig->smtp->ssl) {
                 $mtconf['ssl'] = 'tls';
             }
             $transport = new Zend_Mail_Transport_Smtp($mailConfig->smtp->host, $mtconf);
         } else {
             $transport = new Zend_Mail_Transport_Sendmail();
         }
         Zend_Mail::setDefaultTransport($transport);
         $mail = new Zend_Mail('UTF-8');
         $mail->setFrom($mailConfig->email->noreply, 'FansubCMS Error Report');
         $mail->addTo($mailConfig->email->admin, 'FansubCMS Technical Administrator at' . $_SERVER['HTTP_HOST']);
         $mail->addHeader('X-MailGenerator', 'Log handler on FansubCMS');
         $mail->addHeader('X-Mailer', 'FansubCMS');
         $mail->addHeader('X-Priority', '3');
         $writer = new Zend_Log_Writer_Mail($mail);
         $writer->setSubjectPrependText('FansubCMS Error: ');
     }
     switch (APPLICATION_ENV) {
         case 'debug':
             // is handled by dev bar through
             $writer->addFilter(Zend_Log::DEBUG);
             break;
         case 'testing':
             $writer->addFilter(Zend_Log::NOTICE);
             break;
         default:
             $writer->addFilter(Zend_Log::ERR);
             break;
     }
     $logger = new Zend_Log($writer);
     self::$_logger = $logger;
 }
Exemplo n.º 8
0
 /**
  * Build a log writer which write to the provided email addresses
  *
  * @param array $options an array of options for the log writer,
  * allowed values are (with their default value)
  * - addresses: string or array of email addresses (required)
  * - sender:    email address for the from header
  *              (default: null {@see Zend_Mail::setDefaultFrom})
  * - priority:  a priority filter, (default = Zend_Log::ERR)
  * - project:   an identifier for the current project (default = null)
  * - subject:   a string automatically prepended to subject
  *              (default = 'Errors in project $name')
  *              {@see Zend_Log_Writer_Mail::setSubjectPrependText}
  */
 public function __construct(array $options = array())
 {
     // parse options
     $this->setOptions($options);
     // build a new mail object
     $mail = new Zend_Mail('utf-8');
     if (isset($this->_options['sender'])) {
         $mail->setFrom($this->_options['sender']);
     }
     if (is_string($this->_options['addresses'])) {
         $mail->addTo($this->_options['addresses']);
     } else {
         foreach ($this->_options['addresses'] as $email) {
             $mail->addTo($email);
         }
     }
     parent::__construct($mail, $this->getLayout());
     $this->setLayoutFormatter(new Zle_Log_Formatter_Table());
     $this->setSubjectPrependText($this->_options['subject']);
     $this->addFilter($this->_options['priority']);
 }
Exemplo n.º 9
0
 /**
  * Setup logger
  */
 protected function _initLog()
 {
     if ('development' === APPLICATION_ENV) {
         $writer = new Zend_Log_Writer_Firebug();
     } else {
         if (!empty($this->_options['appSettings']['logger']['email'])) {
             $mail = new Zend_Mail();
             $mail->setFrom($this->_options['appSettings']['logger']['email'])->addTo($this->_options['appSettings']['logger']['email']);
             $writer = new Zend_Log_Writer_Mail($mail);
             // Set subject text for use; summary of number of errors is appended to the subject line before sending the message.
             $writer->setSubjectPrependText('API Application Error has occurred');
         } else {
             $writer = new Zend_Log_Writer_Null();
         }
     }
     return new Zend_Log($writer);
 }
Exemplo n.º 10
0
 /**
  * @group ZF-9990
  */
 public function testFactoryWithCustomLayoutClass()
 {
     $this->getMock('Zend_Layout', null, array(), 'Zend_Stub_Layout_Custom');
     $config = array('layout' => 'Zend_Stub_Layout_Custom');
     $writer = Zend_Log_Writer_Mail::factory($config);
     $this->assertTrue($writer instanceof Zend_Log_Writer_Mail);
 }
Exemplo n.º 11
0
 /**
  * get Logger
  * 
  * @return OSS_Log
  */
 public function getLogger()
 {
     if (null === $this->_logger) {
         // Get Doctrine configuration options from the application.ini file
         $options = $this->getOptions();
         $logger = new OSS_Log();
         if (isset($options['enabled']) && $options['enabled']) {
             foreach ($options['writers'] as $writer => $writerOptions) {
                 switch ($writer) {
                     case 'stream':
                         if (isset($writerOptions['mode']) && ($writerOptions['mode'] = 'single')) {
                             $log_path = $writerOptions['path'];
                             $log_file = $log_path . DIRECTORY_SEPARATOR . (isset($writerOptions['logname']) ? $writerOptions['logname'] : 'log.log');
                         } else {
                             $log_path = $writerOptions['path'] . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m');
                             $log_file = $log_path . DIRECTORY_SEPARATOR . date('Ymd') . '.log';
                         }
                         if (file_exists($log_path) == false) {
                             mkdir($log_path, 0755, true);
                             @chmod($log_path, 0755);
                             @chown($log_path, $writerOptions['owner']);
                             @chgrp($log_path, $writerOptions['group']);
                         }
                         if (file_exists($log_file) == false) {
                             touch($log_file);
                             @chmod($log_file, 0777);
                             @chown($log_file, $writerOptions['owner']);
                             @chgrp($log_file, $writerOptions['group']);
                         }
                         $streamWriter = new Zend_Log_Writer_Stream($log_file);
                         $streamWriter->setFormatter(new Zend_Log_Formatter_Simple('%timestamp% %priorityName% (%priority%) ' . (isset($_SERVER['REMOTE_ADDR']) == true ? "[{$_SERVER['REMOTE_ADDR']}]" : "") . ': %message%' . PHP_EOL));
                         $logger->addWriter($streamWriter);
                         if (isset($writerOptions['level'])) {
                             $logger->addFilter((int) $writerOptions['level']);
                         }
                         break;
                     case 'email':
                         $mail = new Zend_Mail();
                         $mail->setFrom($writerOptions['from'])->addTo($writerOptions['to']);
                         $mailWriter = new Zend_Log_Writer_Mail($mail);
                         // Set subject text for use; summary of number of errors is appended to the
                         // subject line before sending the message.
                         $mailWriter->setSubjectPrependText("[{$writerOptions['prefix']}]");
                         // Only email entries with level requested and higher.
                         $mailWriter->addFilter((int) $writerOptions['level']);
                         $logger->addWriter($mailWriter);
                         break;
                     case 'firebug':
                         if ($writerOptions['enabled']) {
                             $firebugWriter = new Zend_Log_Writer_Firebug();
                             $firebugWriter->addFilter((int) $writerOptions['level']);
                             $logger->addWriter($firebugWriter);
                         }
                         break;
                     default:
                         try {
                             $logger->log("Unknown log writer: {$writer}", Zend_Log::WARN);
                         } catch (Zend_Log_Exception $e) {
                             die("Unknown log writer [{$writer}] during application bootstrap");
                         }
                         break;
                 }
             }
         } else {
             $logger->addWriter(new Zend_Log_Writer_Null());
         }
         try {
             $logger->debug('Logger instantiated', Zend_Log::INFO);
         } catch (Zend_Log_Exception $e) {
             die("Unknown log writer [{$writer}] during application bootstrap");
         }
         $this->_logger = $logger;
     }
     return $this->_logger;
 }
Exemplo n.º 12
0
 protected function _initLog()
 {
     $this->bootstrap('mail');
     $config = $this->getOption('configuration');
     $writer = new \Zend_Log_Writer_Stream($config['log']['file']);
     require_once 'Pkr/Log/Formatter/Advanced.php';
     $formatter = new \Pkr_Log_Formatter_Advanced();
     $writer->setFormatter($formatter);
     $log = new \Zend_Log($writer);
     if (APPLICATION_ENV !== 'development') {
         $mail = new \Zend_Mail('UTF-8');
         $mail->setSubject($config['log']['mail']['subject'])->setFrom($config['log']['mail']['from'])->addTo($config['log']['mail']['to']);
         $writer = new \Zend_Log_Writer_Mail($mail);
         $formatter = new \Pkr_Log_Formatter_Advanced();
         $writer->setFormatter($formatter);
         $log->addWriter($writer);
     }
     return $log;
 }
Exemplo n.º 13
0
 /**
  * Sets the given Zend_Log object into the internal log property.
  * If no log given, a new instance with the internal configuration will be created.
  * @param Enlight_Components_Log|Zend_Log $log
  */
 public function setResource(Zend_Log $log = null)
 {
     if ($log === null) {
         $log = new Enlight_Components_Log();
         $log->setEventItem('date', Zend_Date::now());
         $log->addWriter(new Zend_Log_Writer_Null());
         $config = $this->Config();
         if(!empty($config->logDb)) {
             $writer = Zend_Log_Writer_Db::factory(array(
                 'db' => Shopware()->Db(),
                 'table' => 's_core_log',
                 'columnmap' => array(
                     'type' => 'priority',
                     'key' => 'priorityName',
                     'text' => 'message',
                     'date' => 'date',
                     'ip_address' => 'remote_address',
                     'user_agent' => 'user_agent',
                 )
             ));
             $writer->addFilter(Enlight_Components_Log::WARN);
             $log->addWriter($writer);
         }
         if(!empty($config->logMail)) {
             $mail = new Enlight_Components_Mail();
             $mail->addTo(Shopware()->Config()->Mail);
             $writer = new Zend_Log_Writer_Mail($mail);
             $writer->setSubjectPrependText('Fehler im Shop "'.Shopware()->Config()->Shopname.'" aufgetreten!');
             $writer->addFilter(Enlight_Components_Log::WARN);
             $log->addWriter($writer);
         }
     }
     $this->log = $log;
 }
Exemplo n.º 14
0
 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;
 }
Exemplo n.º 15
0
 /**
  * Initialization Log, Search, KCFinder
  *
  * @return void
  */
 protected function _initLog()
 {
     $params = array();
     //------------------
     $_startTime = microtime(1);
     //Получим конфигурацию
     $config = $this->_options;
     //----- Create Zend_Log object -----
     $columnMapping = array('ts' => 'timestamp', 'msg' => 'message', 'pr' => 'priority', 'pr_name' => 'priorityName');
     $countMsg = $config['logging']['log']['max_rows'];
     $countEx = $config['logging']['exeption']['max_rows'];
     $countStat = $config['logging']['statistics']['max_rows'];
     // Get DB
     $db = Zend_Registry::get('db');
     // Set params
     $params['db'] = $db;
     $params['columnMap'] = $columnMapping;
     // Create writer for DB
     $params['table'] = 'log_msg';
     $params['max_rows'] = $countMsg;
     $writerMsg = new Default_Model_Log($params);
     $params['table'] = 'log_error';
     $params['max_rows'] = $countEx;
     $writerEx = new Default_Model_Log($params);
     $params['table'] = 'log_stat';
     $params['max_rows'] = $countStat;
     $writerStat = new Default_Model_Log($params);
     // Create logers
     $logMsg = new Zend_Log($writerMsg);
     $logEx = new Zend_Log($writerEx);
     $logStat = new Zend_Log($writerStat);
     // Adding new priorities for the $logMsg
     $logMsg->addPriority('LOGIN_OK', 8);
     $logMsg->addPriority('LOGIN_ERR', 9);
     $logMsg->addPriority('LOGOUT', 10);
     $logMsg->addPriority('REG_OK', 11);
     $logMsg->addPriority('REG_ERR', 12);
     $logMsg->addPriority('DETAILS_OK', 13);
     $logMsg->addPriority('FETCHPASS_COMPLETE_OK', 14);
     $logMsg->addPriority('FETCHPASS_COMPLETE_ERR', 15);
     $logMsg->addPriority('FETCHPASS_CONFIRM_OK', 16);
     $logMsg->addPriority('FETCHPASS_CONFIRM_ERR', 17);
     $logMsg->addPriority('MAIL_OK', 18);
     $logMsg->addPriority('MAIL_ERR', 19);
     $logMsg->addPriority('DB_SAVE_ERR', 20);
     $logMsg->addPriority('DB_DELETE_ERR', 21);
     $logMsg->addPriority('POST_EDIT', 22);
     $logMsg->addPriority('POST_SET_STATUS', 23);
     $logMsg->addPriority('ADMIN_POST_EDIT', 24);
     $logMsg->addPriority('ADMIN_ROW_UPDATE', 25);
     $logMsg->addPriority('ADMIN_ROW_INSERT', 26);
     $logMsg->addPriority('ADMIN_ROW_DELETE', 27);
     $logMsg->addPriority('MY_MSG', 28);
     // Adding new priorities for the $logStat
     $logStat->addPriority('LOGIN_OK', 8);
     $logStat->addPriority('LOGIN_ERR', 9);
     $logStat->addPriority('MAIL_OK', 10);
     $logStat->addPriority('FETCHPASS_COMPLETE_OK', 11);
     $logStat->addPriority('FETCHPASS_COMPLETE_ERR', 12);
     $logStat->addPriority('FETCHPASS_CONFIRM_OK', 13);
     $logStat->addPriority('FETCHPASS_CONFIRM_ERR', 14);
     $logStat->addPriority('POST_OPEN', 15);
     $logStat->addPriority('VIDEO_PLAY', 16);
     $logStat->addPriority('AUDIO_PLAY', 17);
     $emailParams = $config['logging']['email'];
     if ($emailParams['send']) {
         $mail = Default_Plugin_SysBox::createMail($emailParams);
         $writer = new Zend_Log_Writer_Mail($mail);
         $my_request = Default_Plugin_SysBox::getUrlRequest();
         if (!$emailParams['subject']) {
             $writer->setSubjectPrependText('Errors request - ' . $my_request);
         }
         $writer->addFilter(Zend_Log::EMERG);
         $writer->addFilter(Zend_Log::ALERT);
         $writer->addFilter(Zend_Log::CRIT);
         $writer->addFilter(Zend_Log::ERR);
         $logger->addWriter($writer);
     }
     // Save to Registry
     Zend_Registry::set("Zend_Log", $logMsg);
     Zend_Registry::set("Zend_LogEx", $logEx);
     Zend_Registry::set("Zend_LogStat", $logStat);
     // Remember in the session array of search results
     $Zend_Auth = Zend_Registry::get("Zend_Auth");
     if (!$Zend_Auth->search) {
         $Zend_Auth->search = array();
     }
     //------------ Configure default search -------------
     // Establish a query analyzer in the coding Utf8
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     //------ Initialization file manager -------------
     Default_Plugin_SysBox::iniKCFinder();
     //---- Defining script execution time ----
     $infoProfiler = Default_Plugin_SysBox::Translate("Время выполнения") . " Bootstrap_initLog(): ";
     Default_Plugin_SysBox::profilerTime2Registry($_startTime, $infoProfiler);
 }