Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Swift Mailer File Logger
- * Please read the LICENSE file
- * @copyright Anton Paramonov <paramonovav@gmail.com>
- * @author Anton Paramonov <paramonovav@gmail.com>
- * @package Swift_Log
- * @license GNU Lesser General Public License
- */
- require_once dirname(__FILE__) . "/../ClassLoader.php";
- Swift_ClassLoader::load("Swift_Log");
- /**
- * The File Logger class
- * @package Swift_Log
- * @author Anton Paramonov <paramonovav@gmail.com>
- */
- class Swift_Log_FileLog extends Swift_Log
- {
- /**
- * Lines in the log
- * @var array
- */
- protected $entries = array();
- /**
- * Open file pointer
- * @var resource
- */
- protected $fl = null;
- /**
- * Init
- * @var string File path where to be save log files
- */
- public function __construct($filepath = '')
- {
- if (empty($filepath))
- {
- throw new Exception("Filepath is empty", 1);
- }
- if (!is_dir($filepath))
- {
- mkdir($filepath, 0777, TRUE);
- }
- $this-> fl = fopen($filepath.'/'.date('Y-m-d').'.swift.log', 'a');
- }
- /**
- * Add a log entry
- * @param string The text for this entry
- * @param string The label for the type of entry
- */
- public function add($text, $type = self::NORMAL)
- {
- $this->entries[] = $type . " " . $text;
- if ($this->getMaxSize() > 0)
- {
- $this->entries = array_slice($this->entries, (-1 * $this->getMaxSize()));
- }
- fwrite($this-> fl, '['.date('Y-m-d H:i:s') .'] - '. $type . " " . $text."\r\n");
- }
- /**
- * Dump the contents of the log to the browser.
- * @param boolean True if the string should be returned rather than output.
- */
- public function dump($return_only=false)
- {
- $ret = implode("\n", $this->entries);
- if (!$return_only) echo $ret;
- else return $ret;
- }
- /**
- * Empty the log
- */
- public function clear()
- {
- $this->failedRecipients = null;
- $this->failedRecipients = array();
- $this->entries = null;
- $this->entries = array();
- }
- public function __destruct()
- {
- $this-> clear();
- fclose($this-> fl);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement