Ei kuvausta

TopLogger.php 774B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class TopLogger
  3. {
  4. public $conf = array(
  5. "separator" => "\t",
  6. "log_file" => ""
  7. );
  8. private $fileHandle;
  9. protected function getFileHandle()
  10. {
  11. if (null === $this->fileHandle)
  12. {
  13. if (empty($this->conf["log_file"]))
  14. {
  15. trigger_error("no log file spcified.");
  16. }
  17. $logDir = dirname($this->conf["log_file"]);
  18. if (!is_dir($logDir))
  19. {
  20. mkdir($logDir, 0777, true);
  21. }
  22. $this->fileHandle = fopen($this->conf["log_file"], "a");
  23. }
  24. return $this->fileHandle;
  25. }
  26. public function log($logData)
  27. {
  28. if ("" == $logData || array() == $logData)
  29. {
  30. return false;
  31. }
  32. if (is_array($logData))
  33. {
  34. $logData = implode($this->conf["separator"], $logData);
  35. }
  36. $logData = $logData. "\n";
  37. fwrite($this->getFileHandle(), $logData);
  38. }
  39. }
  40. ?>