function epLibLog_console($name, $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG) { $this->_id = md5(microtime()); $this->_ident = $ident; //$this->_mask = Log::UPTO($maxLevel); $this->_mask = epLib_Log::UPTO($maxLevel); if (!empty($conf['stream'])) { $this->_stream = $conf['stream']; } if (isset($conf['buffering'])) { $this->_buffering = $conf['buffering']; } if (!empty($conf['lineFormat'])) { $this->_lineFormat = str_replace(array_keys($this->_formatMap), array_values($this->_formatMap), $conf['lineFormat']); } if (!empty($conf['timeFormat'])) { $this->_timeFormat = $conf['timeFormat']; } /* * If output buffering has been requested, we need to register a * shutdown function that will dump the buffer upon termination. */ if ($this->_buffering) { register_shutdown_function(array(&$this, '_Log_console')); } }
/** * Constructs a new Log_file object. * * @param string $name Ignored. * @param string $ident The identity string. * @param array $conf The configuration array. * @param array $maxLevel Maximum priority level at which to log. * @access public */ function epLib_Log_file($name, $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG) { $this->_id = md5(microtime()); $this->_filename = $name; $this->_ident = $ident; //$this->_mask = Log::UPTO($maxLevel); $this->_mask = epLib_Log::UPTO($maxLevel); if (isset($conf['append'])) { $this->_append = $conf['append']; } if (!empty($conf['mode'])) { $this->_mode = $conf['mode']; } if (!empty($conf['lineFormat'])) { $this->_lineFormat = str_replace(array_keys($this->_formatMap), array_values($this->_formatMap), $conf['lineFormat']); } if (!empty($conf['timeFormat'])) { $this->_timeFormat = $conf['timeFormat']; } if (!empty($conf['eol'])) { $this->_eol = $conf['eol']; } else { $this->_eol = strstr(PHP_OS, 'WIN') ? "\r\n" : "\n"; } register_shutdown_function(array(&$this, '_Log_file')); }
/** * Check if the given priority is included in the current level mask. * * @param integer $priority The priority to check. * * @return boolean True if the given priority is included in the current * log mask. * * @access private */ function _isMasked($priority) { return epLib_Log::MASK($priority) & $this->_mask; }
/** * Initialize handlers according to config * @return bool * @throws epExceptionLog * @access private */ private function initialize() { // create the composite handler first if (!$this->composite_handler) { // create the composite handler $this->composite_handler =& epLib_Log::singleton('composite'); if (!$this->composite_handler) { throw new epExceptionLog('Cannot instantiate composite handler'); return false; } } // config the console hander (only on CLI) if (epIsCliRun()) { if ($this->getConfigOption('log_console')) { $this->console_handler =& epLib_Log::singleton('console', '', 'ident', array('stream' => STDOUT)); if (!$this->console_handler) { throw new epExceptionLog('Cannot instantiate log console handler'); return false; } $this->composite_handler->addChild($this->console_handler); } } // config the file hander $log_file = trim($this->getConfigOption('log_file')); if (!empty($log_file)) { $log_file = $this->getAbsolutePath($log_file); $this->file_handler =& epLib_Log::singleton('file', $log_file, 'ident', array('mode' => 0644)); if (!$this->file_handler) { throw new epExceptionLog('Cannot instantiate log file handler'); return false; } $this->composite_handler->addChild($this->file_handler); } return true; }