AllaerdWoocsvLogToFile

Class LogToFile.

Defined (1)

The class is defined in the following location(s).

/include/LogToFile.php  
  1. class LogToFile implements Logger 
  2. /** 
  3. * @var string 
  4. */ 
  5. public $filename = ''; 
  6.  
  7. /** 
  8. * LogToFile constructor. 
  9. * @param $filename 
  10. */ 
  11. public function __construct($filename = null) 
  12. if ($filename) { 
  13. $this->filename = $filename; 
  14.  
  15. /** 
  16. * @param $batch_code 
  17. * @param $data 
  18. */ 
  19. public function log($data) 
  20. $fp = fopen($this->filename, 'a'); 
  21. if (is_array($data) || is_object($data)) { 
  22. $this->writeArray($data, $fp); 
  23. } elseif (is_string($data)) { 
  24. $this->writeString($data, $fp); 
  25. } else { 
  26. $this->writeString('Object could not be converted to a string', $fp); 
  27.  
  28. fclose($fp); 
  29.  
  30. /** 
  31. * @param $data 
  32. * @param $fp 
  33. */ 
  34. public function writeArray($data, $fp) 
  35. fwrite($fp, serialize($data) . PHP_EOL); 
  36.  
  37. /** 
  38. * @param $data 
  39. * @param $fp 
  40. */ 
  41. public function writeString($data, $fp) 
  42. fwrite($fp, $data . PHP_EOL); 
  43.  
  44. /** 
  45. * @param string $filename 
  46. */ 
  47. public function setFilename($filename) 
  48. $this->filename = $filename;