phpist

Untitled

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