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.

53 lines
1.2 KiB

11 years ago
12 years ago
11 years ago
11 years ago
  1. <?php namespace Majestic\Logger;
  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 = \Majestic\Config::get('Logger')->filepath;
  20. }
  21. protected function generateOutString($message)
  22. {
  23. return microtime(true) . " \t: " . $this->pid . trim($message) . "\r\n";
  24. }
  25. protected function concreteLog($message)
  26. {
  27. $out = $this->generateOutString($message);
  28. if (!$this->handler) {
  29. $this->handler = @fopen($this->file_path, "a");
  30. if (!$this->handler) {
  31. throw new \Majestic\Exception\GeneralException('Could not open file ' . $this->file_path);
  32. }
  33. }
  34. fwrite($this->handler, $out);
  35. }
  36. public function __destruct()
  37. {
  38. if ($this->handler) {
  39. if (fclose($this->handler)) {
  40. $this->handler = null;
  41. }
  42. }
  43. }
  44. }