Advertisement
Guest User

Untitled

a guest
Oct 29th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2. /**
  3. * Swift Mailer File Logger
  4. * Please read the LICENSE file
  5. * @copyright Anton Paramonov <paramonovav@gmail.com>
  6. * @author Anton Paramonov <paramonovav@gmail.com>
  7. * @package Swift_Log
  8. * @license GNU Lesser General Public License
  9. */
  10.  
  11. require_once dirname(__FILE__) . "/../ClassLoader.php";
  12. Swift_ClassLoader::load("Swift_Log");
  13.  
  14. /**
  15. * The File Logger class
  16. * @package Swift_Log
  17. * @author Anton Paramonov <paramonovav@gmail.com>
  18. */
  19. class Swift_Log_FileLog extends Swift_Log
  20. {
  21. /**
  22. * Lines in the log
  23. * @var array
  24. */
  25. protected $entries = array();
  26.  
  27. /**
  28. * Open file pointer
  29. * @var resource
  30. */
  31. protected $fl = null;
  32.  
  33. /**
  34. * Init
  35. * @var string File path where to be save log files
  36. */
  37. public function __construct($filepath = '')
  38. {
  39. if (empty($filepath))
  40. {
  41. throw new Exception("Filepath is empty", 1);
  42. }
  43.  
  44. if (!is_dir($filepath))
  45. {
  46. mkdir($filepath, 0777, TRUE);
  47. }
  48.  
  49. $this-> fl = fopen($filepath.'/'.date('Y-m-d').'.swift.log', 'a');
  50. }
  51.  
  52. /**
  53. * Add a log entry
  54. * @param string The text for this entry
  55. * @param string The label for the type of entry
  56. */
  57. public function add($text, $type = self::NORMAL)
  58. {
  59. $this->entries[] = $type . " " . $text;
  60.  
  61. if ($this->getMaxSize() > 0)
  62. {
  63. $this->entries = array_slice($this->entries, (-1 * $this->getMaxSize()));
  64. }
  65.  
  66. fwrite($this-> fl, '['.date('Y-m-d H:i:s') .'] - '. $type . " " . $text."\r\n");
  67. }
  68.  
  69. /**
  70. * Dump the contents of the log to the browser.
  71. * @param boolean True if the string should be returned rather than output.
  72. */
  73. public function dump($return_only=false)
  74. {
  75. $ret = implode("\n", $this->entries);
  76. if (!$return_only) echo $ret;
  77. else return $ret;
  78. }
  79.  
  80. /**
  81. * Empty the log
  82. */
  83. public function clear()
  84. {
  85. $this->failedRecipients = null;
  86. $this->failedRecipients = array();
  87. $this->entries = null;
  88. $this->entries = array();
  89. }
  90.  
  91. public function __destruct()
  92. {
  93. $this-> clear();
  94. fclose($this-> fl);
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement