/Logger

A simple PHP class for logging messages with different log levels and managing log files.

Primary LanguagePHPMIT LicenseMIT

PHP Logger

A simple PHP class for logging messages with different log levels and managing log files.

Usage

  1. Include the Logger class:

    require_once 'Logger.php';
  2. Create a Logger instance:

    $logFileName = 'myapp.log';
    $logger = new Logger($logFileName);
  3. 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.');
  4. Read and display log content:

    $logContent = $logger->readLogs();
    echo nl2br(htmlspecialchars($logContent));
  5. Delete the log file (and create it if it doesn't exist):

    $logger->deleteLogFile();

License

This project is licensed under the MIT License - see the LICENSE file for details.