FileLog.php 871 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace Core\Log;
  3. class FileLog extends AnyLog
  4. {
  5. const DATA_SEPARATOR = ' | ';
  6. const ERROR = 'ERROR';
  7. const INFO = 'INFO';
  8. const DATA = 'DATA';
  9. public static function write($message, $type)
  10. {
  11. $lineArray[] = date('Y-m-d H:i:s');
  12. $lineArray[] = $type;
  13. $lineArray[] = trim($message);
  14. $lineArray[] = "\n";
  15. $file = 'logs/file-' . ((isset($_GET['shop'])) ? str_replace(SHOPIFY_DOMAIN, '', $_GET['shop']): '') . '.log';
  16. // if (!file_exists($file)) {
  17. // touch($file);
  18. // }
  19. file_put_contents($file, implode(self::DATA_SEPARATOR, $lineArray), FILE_APPEND);
  20. }
  21. public static function getFile()
  22. {
  23. $file = 'logs/file-' . ((isset($_GET['shop'])) ? str_replace(SHOPIFY_DOMAIN, '', $_GET['shop']): '') . '.log';
  24. return $file;
  25. }
  26. }