The web based syslog https://lggr.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8KB

  1. <?php
  2. /* speichern als UTF8 ohne BOM */
  3. class LggrCsv {
  4. private $lggr = null;
  5. const PROPERTIES = [
  6. 'id',
  7. 'date',
  8. 'facility',
  9. 'level',
  10. 'host',
  11. 'program',
  12. 'pid',
  13. 'message'
  14. ];
  15. function __construct(Lggr &$oLggr) {
  16. $this->lggr = & $oLggr;
  17. }
  18. // constructor
  19. private function generiereDateiname() {
  20. return 'lggrarchive_' . date('Ymd') . '.csv';
  21. }
  22. function generiere() {
  23. header('Content-Type: text/csv; charset=utf-8');
  24. header(
  25. 'Content-Disposition: attachment; filename="' .
  26. $this->generiereDateiname() . '"');
  27. $iCnt = 0;
  28. $aEntries = $this->lggr->getArchived(0, 9999);
  29. foreach ($aEntries as $entry) {
  30. if (0 == $iCnt) {
  31. // Spaltentitel
  32. foreach (self::PROPERTIES as $sProp) {
  33. echo $sProp . ";";
  34. } // foreach
  35. echo "\n";
  36. } // if 0
  37. // Wertespalten
  38. foreach (self::PROPERTIES as $sProp) {
  39. $sValue = $entry->$sProp;
  40. switch ($sProp) {
  41. case 'id':
  42. echo "$sValue;";
  43. break;
  44. case 'message':
  45. echo '"' . strtr(utf8_decode($sValue), '"', "'") . "\";";
  46. break;
  47. default:
  48. echo '"' . utf8_decode($sValue) . "\";";
  49. break;
  50. } // switch
  51. } // foreach
  52. echo "\n";
  53. $iCnt ++;
  54. } // foreach
  55. } // function
  56. } // class
Social stuff:
Mastodon