<?php

namespace App\Libraries;

class LogCollector
{
  private static array $_logBuffers = [];

  static public function log(string $message, string $level = "info"): void
  {
    self::$_logBuffers[] = sprintf("%s[%s]: %s", date("H:i:s"), $level, $message);
    log_message($level, $message);
  }
  static public function info(string $message): void
  {
    self::log($message, 'info');
  }
  static public function error(string $message): void
  {
    self::log($message,  'error');
  }
  static public function warning(string $message): void
  {
    self::log($message, 'warning');
  }
  static public function debug(string $message): void
  {
    self::log($message, 'debug');
  }
  static public function dump(): string
  {
    return implode("\n", self::$_logBuffers);
  }

  public static function clear(): void
  {
    self::$_logBuffers = [];
  }
}
