Changeset 7637 for trunk/src/inc/LogHandler.class.php
- Timestamp:
- Mar 31, 2010, 1:32:46 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/inc/LogHandler.class.php
r7631 r7637 8 8 /* 9 9 * Log levels: 10 * LOG_EMERG System is unusable11 * LOG_ALERT Action must be taken immediately12 * LOG_CRIT Critical conditions13 * LOG_ERR Error conditions14 * LOG_WARNING Warning conditions15 * LOG_NOTICE Normal, but significant, condition16 * LOG_INFO Informational message17 * LOG_DEBUG Debug-level message10 * SYSLOG_EMERG System is unusable 11 * SYSLOG_ALERT Action must be taken immediately 12 * SYSLOG_CRIT Critical conditions 13 * SYSLOG_ERR Error conditions 14 * SYSLOG_WARNING Warning conditions 15 * SYSLOG_NOTICE Normal, but significant, condition 16 * SYSLOG_INFO Informational message 17 * SYSLOG_DEBUG Debug-level message 18 18 */ 19 20 define('SYSLOG_NONE', 0); 21 define('SYSLOG_EMERG', 1); 22 define('SYSLOG_ALERT', 2); 23 define('SYSLOG_CRIT', 3); 24 define('SYSLOG_ERR', 4); 25 define('SYSLOG_WARNING', 5); 26 define('SYSLOG_NOTICE', 6); 27 define('SYSLOG_INFO', 7); 28 define('SYSLOG_DEBUG', 8); 29 30 /* 31 * Actions on log levels 32 */ 33 define('LOG_LEVEL_ECHO', SYSLOG_DEBUG); 34 define('LOG_LEVEL_WRITE', SYSLOG_DEBUG); 35 define('LOG_LEVEL_MAIL', SYSLOG_DEBUG); 19 36 20 37 class LogHandler { 21 38 /* 22 * Function: LogHandler 39 * Function: __construct (constructor) 40 * Parameters: - 41 * Function: Creating a LogHandler object 42 */ 43 public function __construct() { 44 } 45 46 /* 47 * Function: logEntry 23 48 * Parameters: int $logno, string $logstr, string $logfile, int $logline 24 * Function: Handling with log entries, decides what to do with it 49 * Function: Handling with log entries, decides what to do with it 25 50 */ 26 public function LogHandler(int $logno, string $logstr, string $logfile, int $logline) { 51 public function logEntry($logno, $logstr, $logfile, $logline) { 52 $errorString = 'SysLog '; 53 27 54 switch ($logno) { 28 case LOG_EMERG: 29 echo 'LOG_EMERG: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 30 // TODO 55 case SYSLOG_EMERG: 56 $errorString = 'Emergency'; 31 57 break; 32 case LOG_ALERT: 33 echo 'LOG_ALERT: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 34 // TODO 58 case SYSLOG_ALERT: 59 $errorString = 'Alert'; 35 60 break; 36 case LOG_CRIT: 37 echo 'LOG_CRIT: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 38 // TODO 61 case SYSLOG_CRIT: 62 $errorString = 'Critical'; 39 63 break; 40 case LOG_ERR: 41 echo 'LOG_ERR: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 42 // TODO 64 case SYSLOG_ERR: 65 $errorString = 'Error'; 43 66 break; 44 case LOG_WARNING: 45 echo 'LOG_WARNING: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 46 // TODO 67 case SYSLOG_WARNING: 68 $errorString = 'Warning'; 47 69 break; 48 case LOG_NOTICE: 49 echo 'LOG_NOTICE: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 50 // TODO 70 case SYSLOG_NOTICE: 71 $errorString = 'Notice'; 51 72 break; 52 case LOG_INFO: 53 echo 'LOG_INFO: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 54 // TODO 73 case SYSLOG_INFO: 74 $errorString = 'Information'; 55 75 break; 56 case LOG_DEBUG: 57 echo 'LOG_DEBUG: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 58 // TODO 76 case SYSLOG_DEBUG: 77 $errorString = 'Debug'; 59 78 break; 60 79 default: 61 echo 'LOG_DEFAULT: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 62 // TODO 80 $errorString = 'SYSLOG_DEFAULT'; 63 81 break; 82 } 83 84 $errorString .= ' (' . $logno . '): ' . $logstr . "\r\n\t" . 'In file "' . $logfile . '" on line "' . $logline . '"' . "\r\n"; 85 86 if ($logno <= LOG_LEVEL_ECHO) { 87 echo $errorString; 88 } 89 if ($logno <= LOG_LEVEL_WRITE) { 90 // TODO: Write $errorString to file 91 } 92 if ($logno <= LOG_LEVEL_MAIL) { 93 // TODO: Mail $errorString to administrator 64 94 } 65 95 } 66 96 } 97 98 $LOG_HANDLER = new LogHandler(); 99 100 /* 101 * Function: trigger_log 102 * Parameters: int $logno, string $logstr, string $logfile, int $logline 103 * Function: Handling with log entries, forwarding them to our $LOG_HANDLER object. 104 */ 105 function trigger_log($logno, $logstr, $logfile, $logline) { 106 global $LOG_HANDLER; 107 108 $LOG_HANDLER->logEntry($logno, $logstr, $logfile, $logline); 109 } 67 110 ?>
Note:
See TracChangeset
for help on using the changeset viewer.