|  | ||
|---|---|---|
| .. | ||
| controllers | ||
| models | ||
| views | ||
| README.md | ||
| bootstrap.php | ||
| plugin.json | ||
		
			
				
				README.md
			
		
		
			
			
		
	
	Logger plugin
Overview
The Logger plugin provides a modular, pluggable logging system for the application.
It logs user and system events to a MySQL table named log.
Installation
- Copy the entire loggerfolder into your project'splugins/directory.
- Ensure "enabled": trueinplugins/logger/plugin.json.
- On first initialization, the plugin will create the logtable if it does not already exist.
Database Schema
The plugin defines the following table (auto-created):
CREATE TABLE IF NOT EXISTS `log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `scope` SET('user','system') NOT NULL,
  `message` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
Hook API
Core must call:
// After DB connect:
do_hook('logger.system_init', ['db' => $db]);
The plugin listens on logger.system_init, runs auto-migration, then sets:
$GLOBALS['logObject']; // instance of Log
$GLOBALS['user_IP'];  // current user IP
Then in the code use:
$logObject->insertLog($userId, 'Your message', 'user');
$data = $logObject->readLog($userId, 'user', $offset, $limit, $filters);
File Structure
plugins/logger/
├─ bootstrap.php        # registers hook
├─ plugin.json          # metadata & enabled flag
├─ README.md            # this documentation
├─ models/
│   ├─ Log.php          # main Log class
│   └─ LoggerFactory.php# migration + factory
├─ helpers/
│   └─ logs.php         # user IP helper
└─ migrations/
    └─ create_log_table.sql
Uninstall / Disable
- Set "enabled": falseinplugin.jsonor delete theplugins/logger/folder.
- Core code will default to NullLoggerand no logs will be written.