Documentation is available at class.Logger.inc
- <?php //-*-php-*-
- /* ******************************************************************** **
- ** Copyright notice **
- ** **
- ** (c) 1995-2003 PHPOpenChat Development Team **
- ** http://phpopenchat.sourceforge.net/ **
- ** **
- ** All rights reserved **
- ** **
- ** This script is part of the PHPOpenChat project. The PHPOpenChat **
- ** project is free software; you can redistribute it and/or modify **
- ** it under the terms of the GNU General Public License as published by **
- ** the Free Software Foundation; either version 2 of the License, or **
- ** (at your option) any later version. **
- ** **
- ** The GNU General Public License can be found at **
- ** http://www.gnu.org/copyleft/gpl.html. **
- ** A copy is found in the textfile GPL and important notices to the **
- ** license from the team is found in the textfile LICENSE distributed **
- ** with these scripts. **
- ** **
- ** This script is distributed in the hope that it will be useful, **
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
- ** GNU General Public License for more details. **
- ** **
- ** This copyright notice MUST APPEAR in all copies of the script! **
- ** ******************************************************************** */
- //Get default values
- require_once(POC_BASE.'/config.inc.php');
- /**
- * Implements a logging mechanism
- *
- * @package phpopenchat
- * @author Michael Oertel <michael@ortelius.de>
- * @access public
- * @version $Id: class.Logger.inc,v 1.16 2003/10/18 08:39:03 letreo Exp $
- */
- class Logger
- {
- /**
- * Constructor
- *
- * @access public
- */
- function Logger()
- {
- }
- /**
- * Writes lines into the log file
- *
- * @access private
- * @return void
- */
- function _write( $case, $message, $file = '', $line = '' )
- {
- if( NO_LOGGING ) return null;
- define_syslog_variables();
- $file = ($file!='')? $file.':'.$line.' ' : '';
- //mo, check for user-ip exists in Chatter::go_online()
- if( isset($_SESSION['chatter']) ) {
- $ip = $_SESSION['chatter']->get_last_IP();
- } else {
- $ip = (isset($_SERVER['REMOTE_ADDR']))? $_SERVER['REMOTE_ADDR'] : '-' ;
- }
- $log = rtrim("$ip $file $message").NL;
- if ( LOG_TO_FILE ) {
- $fh=fopen(LOG_TO_FILE, "a");
- fwrite($fh, date("Y-m-d H:i:s"). " $case $log");
- fclose($fh);
- }
- if ( LOG_TO_SYSLOG ) {
- openlog('[POC-'.$case.']', LOG_PERROR, LOG_SYSLOG_FACIL);
- switch($case)
- {
- case 'INFO': syslog(LOG_INFO, $log); break;
- case 'LINE': syslog(LOG_INFO, $log); break;
- case 'POST': syslog(LOG_INFO, $log); break;
- case 'DEBUG': syslog(LOG_DEBUG, $log); break;
- case 'WARNING':syslog(LOG_WARNING, $log); break;
- case 'ERROR': syslog(LOG_ERR, $log); break;
- case 'EMERG': syslog(LOG_EMERG, $log); break;
- }
- closelog();
- }
- }
- function history_raw ( $input ) {
- if ( NO_LOGGING || !LOG_TO_FILE || ! LOGFILE_HISTORY_RAW ) return null;
- if (! $fh=fopen(LOGFILE_HISTORY_RAW, "a") ) {
- $_SESSION['logger']->error("can not open".LOGFILE_HISTORY_RAW );
- }
- $log.= date ("Y-m-d H:i:s", $input->get_date() );
- $log.= " ".$input->get_ip();
- $log.= " [" . $input->get_channel() . "] " ;
- $chatter=$input->get_chatter();
- $log.=$chatter->get_nick();
- unset($chatter);
- $log .= $input->get_whispered() == 'on' ? " w" : " s" ;
- $log.= " to ".$input->get_recipient() . ":" ;
- $log .= " ". $input->get_line();
- fwrite($fh, $log."\n");
- fclose($fh);
- unset($log);
- }
- function history_html ( $input ) {
- if ( ! LOGFILE_HISTORY_HTML ) return null;
- $_SESSION['logger']->debug("hist-html:".$input);
- }
- /**
- * Loggs info messages
- *
- * @access public
- */
- function info( $message )
- {
- if( !LOG_POC_INFOS ) return null;
- $this->_write('INFO',$message);
- }
- /**
- * Loggs lines
- *
- * @access public
- */
- function line($message)
- {
- if( !LOG_POC_LINES ) return null;
- $this->_write('LINE',$message);
- }
- /**
- * Loggs raw posts
- *
- * @access public
- */
- function raw_post($message)
- {
- if( !LOG_POC_RAW_POST ) return null;
- $this->_write('POST',$message);
- }
- /**
- * Loggs debug messages
- *
- * @access public
- */
- function debug($message, $file = '' , $line = '')
- {
- if( !LOG_POC_DEBUG ) return null;
- $this->_write('DEBUG',$message, $file, $line);
- }
- /**
- * Loggs warnings
- *
- * warning conditions
- *
- * @access public
- */
- function warning($message)
- {
- if( !LOG_POC_WARNING ) return null;
- $this->_write('WARNING',$message);
- }
- /**
- * Loggs errors
- *
- * error conditions
- *
- * @access public
- */
- function error($message, $file = '' , $line = '')
- {
- if( !LOG_POC_ERROR ) return null;
- $this->_write('ERROR',$message, $file, $line);
- }
- /**
- * Loggs emergency errors
- *
- * system is unusable
- *
- * @access public
- */
- function emerg($message, $file = '' , $line = '')
- {
- if( !LOG_POC_EMERG ) return null;
- $this->_write('EMERG',$message, $file, $line);
- }
- /**
- * Loggs traffic
- *
- * @access public
- * @param integer
- * @return mixed
- */
- function traffic( $content_length = 0 )
- {
- if( !LOG_POC_TRAFFIC || NO_LOGGING ) return null;
- //if( !$_SESSION['chat']->check_php_version( '4.3.0' ) ) return null;
- if( php_sapi_name() == 'cgi' ) return null;
- if( !function_exists('apache_response_headers') ) return null;
- if( !is_int($content_length) ) die('Integer expected!');
- $bytes_in = 0;
- $bytes_out = 0;
- $headers_out = apache_response_headers();
- if( is_array($headers_out) ) {
- foreach( $headers_out as $key => $value ) {
- $bytes_out += strlen($key) + strlen($value);
- }
- }
- $headers_in = apache_request_headers();
- if( is_array($headers_in) ) {
- foreach( $headers_in as $key => $value ) {
- $bytes_in += strlen($key) + strlen($value);
- }
- }
- $bytes_out += $content_length;
- $_SESSION['chat']->connect();
- $_SESSION['chat']->log_traffic( $bytes_in, $bytes_out );
- $_SESSION['chat']->disconnect();
- }
- }
- ?>
Documentation generated on Tue, 29 Jun 2004 14:42:09 +0200 by phpDocumentor 1.3.0RC3