LoggerAppenderDailyFile.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * log4php is a PHP port of the log4j java logging package.
  4. *
  5. * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
  6. * <p>Design, strategies and part of the methods documentation are developed by log4j team
  7. * (Ceki Gülcü as log4j project founder and
  8. * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
  9. *
  10. * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
  11. * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
  12. *
  13. * <p>This software is published under the terms of the LGPL License
  14. * a copy of which has been included with this distribution in the LICENSE file.</p>
  15. *
  16. * @package log4php
  17. * @subpackage appenders
  18. */
  19. /**
  20. * @ignore
  21. */
  22. if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  23. require_once(LOG4PHP_DIR . '/appenders/LoggerAppenderFile.php');
  24. /**
  25. * LoggerAppenderDailyFile appends log events to a file ne.
  26. *
  27. * A formatted version of the date pattern is used as to create the file name
  28. * using the {@link PHP_MANUAL#sprintf} function.
  29. * <p>Parameters are {@link $datePattern}, {@link $file}. Note that file
  30. * parameter should include a '%s' identifier and should always be set
  31. * before {@link $file} param.</p>
  32. *
  33. * @author Abel Gonzalez <agonzalez@lpsz.org>
  34. * @version $Revision: 1.1 $
  35. * @package log4php
  36. * @subpackage appenders
  37. */
  38. class LoggerAppenderDailyFile extends LoggerAppenderFile {
  39. /**
  40. * Format date.
  41. * It follows the {@link PHP_MANUAL#date()} formatting rules and <b>should always be set before {@link $file} param</b>.
  42. * @var string
  43. */
  44. var $datePattern = "Ymd";
  45. /**
  46. * Constructor
  47. *
  48. * @param string $name appender name
  49. */
  50. function LoggerAppenderDailyFile($name)
  51. {
  52. $this->LoggerAppenderFile($name);
  53. }
  54. /**
  55. * Sets date format for the file name.
  56. * @param string $format a regular date() string format
  57. */
  58. function setDatePattern ( $format )
  59. {
  60. $this->datePattern = $format;
  61. }
  62. /**
  63. * @return string returns date format for the filename
  64. */
  65. function getDatePattern ( )
  66. {
  67. return $this->datePattern;
  68. }
  69. /**
  70. * The File property takes a string value which should be the name of the file to append to.
  71. * Sets and opens the file where the log output will go.
  72. *
  73. * @see LoggerAppenderFile::setFile()
  74. */
  75. function setFile()
  76. {
  77. $numargs = func_num_args();
  78. $args = func_get_args();
  79. if ($numargs == 1 and is_string($args[0])) {
  80. parent::setFile( sprintf((string)$args[0], date($this->getDatePattern())) );
  81. } elseif ($numargs == 2 and is_string($args[0]) and is_bool($args[1])) {
  82. parent::setFile( sprintf((string)$args[0], date($this->getDatePattern())), $args[1] );
  83. }
  84. }
  85. }
  86. ?>