Log_Model.php 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class Log_Model extends Model {
  3. private $date;
  4. private $level;
  5. private $information;
  6. public function date () {
  7. return $this->date;
  8. }
  9. public function level () {
  10. return $this->level;
  11. }
  12. public function info () {
  13. return $this->information;
  14. }
  15. public function _date ($date) {
  16. $this->date = $date;
  17. }
  18. public function _level ($level) {
  19. $this->level = $level;
  20. }
  21. public function _info ($information) {
  22. $this->information = $information;
  23. }
  24. }
  25. class LogDAO extends Model_txt {
  26. public function __construct () {
  27. parent::__construct (LOG_PATH . '/application.log', 'r+');
  28. }
  29. public function lister () {
  30. $logs = array ();
  31. while (($line = $this->readLine ()) !== false) {
  32. if (preg_match ('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) {
  33. $myLog = new Log_Model ();
  34. $myLog->_date ($matches[1]);
  35. $myLog->_level ($matches[2]);
  36. $myLog->_info ($matches[3]);
  37. $logs[] = $myLog;
  38. }
  39. }
  40. return $logs;
  41. }
  42. }