[7661] | 1 | <?php
|
---|
[7618] | 2 | /*
|
---|
| 3 | * Project: NodeMap2.0
|
---|
| 4 | * File: LogHandler.class.php
|
---|
| 5 | * Purpose: Handling our log file containing log entries generated by the application
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * Log levels:
|
---|
[7637] | 10 | * 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
|
---|
[7618] | 18 | */
|
---|
| 19 |
|
---|
[7637] | 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);
|
---|
| 36 |
|
---|
[7618] | 37 | class LogHandler {
|
---|
| 38 | /*
|
---|
[7637] | 39 | * Function: __construct (constructor)
|
---|
| 40 | * Parameters: -
|
---|
| 41 | * Function: Creating a LogHandler object
|
---|
| 42 | */
|
---|
| 43 | public function __construct() {
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * Function: logEntry
|
---|
[7618] | 48 | * Parameters: int $logno, string $logstr, string $logfile, int $logline
|
---|
[7637] | 49 | * Function: Handling with log entries, decides what to do with it
|
---|
[7618] | 50 | */
|
---|
[7637] | 51 | public function logEntry($logno, $logstr, $logfile, $logline) {
|
---|
| 52 | $errorString = 'SysLog ';
|
---|
| 53 |
|
---|
[7618] | 54 | switch ($logno) {
|
---|
[7637] | 55 | case SYSLOG_EMERG:
|
---|
| 56 | $errorString = 'Emergency';
|
---|
[7618] | 57 | break;
|
---|
[7637] | 58 | case SYSLOG_ALERT:
|
---|
| 59 | $errorString = 'Alert';
|
---|
[7618] | 60 | break;
|
---|
[7637] | 61 | case SYSLOG_CRIT:
|
---|
| 62 | $errorString = 'Critical';
|
---|
[7618] | 63 | break;
|
---|
[7637] | 64 | case SYSLOG_ERR:
|
---|
| 65 | $errorString = 'Error';
|
---|
[7618] | 66 | break;
|
---|
[7637] | 67 | case SYSLOG_WARNING:
|
---|
| 68 | $errorString = 'Warning';
|
---|
[7618] | 69 | break;
|
---|
[7637] | 70 | case SYSLOG_NOTICE:
|
---|
| 71 | $errorString = 'Notice';
|
---|
[7618] | 72 | break;
|
---|
[7637] | 73 | case SYSLOG_INFO:
|
---|
| 74 | $errorString = 'Information';
|
---|
[7618] | 75 | break;
|
---|
[7637] | 76 | case SYSLOG_DEBUG:
|
---|
| 77 | $errorString = 'Debug';
|
---|
[7618] | 78 | break;
|
---|
| 79 | default:
|
---|
[7637] | 80 | $errorString = 'SYSLOG_DEFAULT';
|
---|
[7618] | 81 | break;
|
---|
| 82 | }
|
---|
[7637] | 83 |
|
---|
| 84 | $errorString .= ' (' . $logno . '): ' . $logstr . "\r\n\t" . 'In file "' . $logfile . '" on line "' . $logline . '"' . "\r\n";
|
---|
| 85 |
|
---|
| 86 | if ($logno <= LOG_LEVEL_ECHO) {
|
---|
[7721] | 87 | // TODO: David: Make it possible to echo as comment in a KML, HTML, SQL or an other file
|
---|
[7637] | 88 | echo $errorString;
|
---|
| 89 | }
|
---|
| 90 | if ($logno <= LOG_LEVEL_WRITE) {
|
---|
[7720] | 91 | // TODO: David: Write $errorString to file
|
---|
[7637] | 92 | }
|
---|
| 93 | if ($logno <= LOG_LEVEL_MAIL) {
|
---|
[7720] | 94 | // TODO: David: Mail $errorString to administrator
|
---|
[7637] | 95 | }
|
---|
[7618] | 96 | }
|
---|
| 97 | }
|
---|
[7637] | 98 |
|
---|
| 99 | $LOG_HANDLER = new LogHandler();
|
---|
| 100 |
|
---|
| 101 | /*
|
---|
| 102 | * Function: trigger_log
|
---|
| 103 | * Parameters: int $logno, string $logstr, string $logfile, int $logline
|
---|
| 104 | * Function: Handling with log entries, forwarding them to our $LOG_HANDLER object.
|
---|
| 105 | */
|
---|
| 106 | function trigger_log($logno, $logstr, $logfile, $logline) {
|
---|
| 107 | global $LOG_HANDLER;
|
---|
| 108 |
|
---|
| 109 | $LOG_HANDLER->logEntry($logno, $logstr, $logfile, $logline);
|
---|
| 110 | }
|
---|
[7618] | 111 | ?>
|
---|