phpist

Untitled

Oct 24th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1.  
  2.  
  3. Листинг 23.1. Базовый класс. Файл File/Logger.php
  4. <?php ## Базовый класс
  5. class FileLogger
  6. {
  7. public $f;
  8. // открытый файл
  9. public $name;
  10. // имя журнала
  11. public $lines = []; // накапливаемые строки
  12. public $t;
  13. public function __construct($name, $fname)
  14. {
  15. $this->name = $name;
  16. $this->f = fopen($fname, "a+");
  17. }
  18. public function __destruct()
  19. {
  20. fputs($this->f, join("", $this->lines));
  21. fclose($this->f);
  22. }
  23. public function log($str)
  24. {
  25. $prefix = "[".date("Y-m-d_h:i:s ")."{$this->name}] ";
  26. $str = preg_replace('/^/m', $prefix, rtrim($str));
  27. $this->lines[] = $str."\n";
  28. }
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment