log.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. Copyright (c) 2009-2017 F3::Factory/Bong Cosca, All rights reserved.
  4. This file is part of the Fat-Free Framework (http://fatfreeframework.com).
  5. This is free software: you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the Free Software
  7. Foundation, either version 3 of the License, or later.
  8. Fat-Free Framework is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with Fat-Free Framework. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. //! Custom logger
  16. class Log {
  17. protected
  18. //! File name
  19. $file;
  20. /**
  21. * Write specified text to log file
  22. * @return string
  23. * @param $text string
  24. * @param $format string
  25. **/
  26. function write($text,$format='r') {
  27. $fw=Base::instance();
  28. $fw->write(
  29. $this->file,
  30. date($format).
  31. (isset($_SERVER['REMOTE_ADDR'])?
  32. (' ['.$_SERVER['REMOTE_ADDR'].']'):'').' '.
  33. trim($text).PHP_EOL,
  34. TRUE
  35. );
  36. }
  37. /**
  38. * Erase log
  39. * @return NULL
  40. **/
  41. function erase() {
  42. @unlink($this->file);
  43. }
  44. /**
  45. * Instantiate class
  46. * @param $file string
  47. **/
  48. function __construct($file) {
  49. $fw=Base::instance();
  50. if (!is_dir($dir=$fw->LOGS))
  51. mkdir($dir,Base::MODE,TRUE);
  52. $this->file=$dir.$file;
  53. }
  54. }