Introduction
To get a standardised logging system throughout the admin we should adapt the PEAR::Log wat of
doing things
Usage
Within the config a call is made to initiate the logger with the logged in Users ID as the ident
for all the logging transactions. Currently this requires a DSN
if (isset($_SESSION['admin_user_id'])) {
$conf['db'] = $conn;
$logger = &Log::factory('sql', 'log_table',
$_SESSION['admin_user_id'], $conf);
} else {
$conf['db'] = $conn;
$logger = &Log::factory('sql', 'log_table',
'system', $conf);
}
To log a message simply call the logger:
$logger->log('Changed Site to ' . $_POST['view_site'],
PEAR_LOG_ALERT);
Use of the pear standard logging IDs is required.
- ID Level Shortcut Description
- 0 PEAR_LOG_EMERG emerg() System is unusable
- 1 PEAR_LOG_ALERT alert() Immediate action required
- 2 PEAR_LOG_CRIT crit() Critical conditions
- 3 PEAR_LOG_ERR err() Error conditions
- 4 PEAR_LOG_WARNING warning() Warning conditions
- 5 PEAR_LOG_NOTICE notice() Normal but significant
- 6 PEAR_LOG_INFO info() Informational
- 7 PEAR_LOG_DEBUG debug() Debug-level messages
The DB table to use with logger is as follows
CREATE TABLE `log_table` (
`id` smallint(5) unsigned NOT NULL auto_increment,
`logtime` timestamp NOT NULL default CURRENT_TIMESTAMP
on update CURRENT_TIMESTAMP,
`ident` char(16) NOT NULL,
`priority` tinyint(3) unsigned NOT NULL default '6',
`message` varchar(200) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
ToDo
- Tidy up the connection / instantiation element
- Log the time as a UNIX Timestamp and not a mySQL time.
- Change the DB structure.
External Links
|