phpist

Untitled

Oct 24th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 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('1', '2');
  28. // echo $gg->log();
  29. echo $gg;
  30. unset($gg);
  31.  
  32. //$gg->name = 314;
  33. //$gg->f = 101;
  34.  
  35. //unset($gg);// unset();
  36. //$gg = new FileLogger;
  37. //unset($gg);
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment