log.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. Copyright (c) 2009-2014 F3::Factory/Bong Cosca, All rights reserved.
  4. This file is part of the Fat-Free Framework (http://fatfree.sf.net).
  5. THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF
  6. ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  7. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  8. PURPOSE.
  9. Please see the license.txt file for more information.
  10. */
  11. //! Custom logger
  12. class Log {
  13. protected
  14. //! File name
  15. $file;
  16. /**
  17. * Write specified text to log file
  18. * @return string
  19. * @param $text string
  20. * @param $format string
  21. **/
  22. function write($text,$format='r') {
  23. $fw=Base::instance();
  24. $fw->write(
  25. $this->file,
  26. date($format).
  27. (isset($_SERVER['REMOTE_ADDR'])?
  28. (' ['.$_SERVER['REMOTE_ADDR'].']'):'').' '.
  29. trim($text).PHP_EOL,
  30. TRUE
  31. );
  32. }
  33. /**
  34. * Erase log
  35. * @return NULL
  36. **/
  37. function erase() {
  38. @unlink($this->file);
  39. }
  40. /**
  41. * Instantiate class
  42. * @param $file string
  43. **/
  44. function __construct($file) {
  45. $fw=Base::instance();
  46. if (!is_dir($dir=$fw->get('LOGS')))
  47. mkdir($dir,Base::MODE,TRUE);
  48. $this->file=$dir.$file;
  49. }
  50. }