Log.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. $i = 0;
  32. while (($line = $this->readLine ()) !== false) {
  33. $logs[$i] = new Log_Model ();
  34. $logs[$i]->_date (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\1", $line));
  35. $logs[$i]->_level (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\2", $line));
  36. $logs[$i]->_info (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\3", $line));
  37. $i++;
  38. }
  39. return $logs;
  40. }
  41. }