A simple PHP class for logging messages with different log levels and managing log files.
-
Include the Logger class:
require_once 'Logger.php';
-
Create a Logger instance:
$logFileName = 'myapp.log'; $logger = new Logger($logFileName);
-
Log messages:
-
Log an "INFO" level message:
$logger->info('This is an INFO message.');
-
Log a "DEBUG" level message:
$logger->debug('This is a DEBUG message.');
-
Log an "ERROR" level message:
$logger->error('This is an ERROR message.');
-
Log a "WARNING" level message:
$logger->warning('This is a WARNING message.');
-
-
Read and display log content:
$logContent = $logger->readLogs(); echo nl2br(htmlspecialchars($logContent));
-
Delete the log file (and create it if it doesn't exist):
$logger->deleteLogFile();
This project is licensed under the MIT License - see the LICENSE file for details.