You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.0 KiB

12 years ago
  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Logger
  7. * @since 21-11-2011
  8. * @user: agrebnev
  9. */
  10. class FileLogger extends Logger
  11. {
  12. protected $file_path = '';
  13. /**
  14. * @var resource
  15. */
  16. protected $handler = null;
  17. protected function __construct()
  18. {
  19. $this->file_path = Config::get('Logger')->filepath;
  20. }
  21. protected function concreteLog($message)
  22. {
  23. $out = microtime(true) . " \t: " . $this->pid . trim($message) . "\r\n";
  24. if (!$this->handler) {
  25. $this->handler = @fopen($this->file_path, "a");
  26. if (!$this->handler) {
  27. throw new GeneralException('Could not open file ' . $this->file_path);
  28. }
  29. }
  30. fwrite($this->handler, $out);
  31. }
  32. public function __destruct()
  33. {
  34. if ($this->handler) {
  35. if (fclose($this->handler)) {
  36. $this->handler = null;
  37. }
  38. }
  39. }
  40. }