Exemplo n.º 1
0
 /**
  * Construct a new instance of this handler.
  *
  * \param string $filename
  *      Name of the log file to write to.
  *
  * \param int $maxBytes
  *      The maximum size the log file may occupy, in bytes.
  *
  * \param int $backupCount
  *      (optional) Specifies how many backup logs are kept
  *      alongside the current log file.
  *      Backup logs are named after the date and time
  *      at which they were created. The exact format
  *      depends on the value of the \a $when parameter.
  *      The default value is 0, which disables deletion
  *      of old backups.
  *
  * \param string $mode
  *      (optional) Mode to use when opening
  *      the file. Defauts to "at" (append).
  *
  * \param bool $delay
  *      (optional) Whether to delay the actual
  *      opening of the file until the first write.
  *      Defaults to \a false (no delay).
  *
  * \note
  *      Depending on your installation, values bigger
  *      than 1\<\<31 (2 GB) for the \a $maxBytes parameter
  *      may not work correctly.
  */
 public function __construct($filename, $maxBytes = 0, $backupCount = 0, $mode = 'a', $delay = 0)
 {
     if ($maxBytes > 0) {
         $mode = 'a';
     }
     parent::__construct($filename, $mode, $delay);
     $this->maxBytes = $maxBytes;
     $this->backupCount = $backupCount;
 }
Exemplo n.º 2
0
 /**
  * Construct a new instance of this handler.
  *
  * \param string $filename
  *      Name of the log file to write to.
  *
  * \param string $when
  *      (optional) A log rotation specification,
  *      which acts as a multiplier for the \a $interval
  *      parameter. The default value is "h".
  *      Valid (case-insensitive) values include
  *      -   "s" -- rotate the logs every \a $interval
  *          seconds.
  *      -   "m" -- rotate the logs every \a $interval
  *          minutes.
  *      -   "h" -- rotate the logs every \a $interval
  *          hours.
  *      -   "d" -- rotate the logs every \a $interval
  *          days.
  *      -   "w0" through "w6" -- rotate the logs every
  *          \a $interval weeks. The number after the "w"
  *          character indicates on what day of the week
  *          the log rotation will happen (0 means Monday,
  *          1 means Tuesday and so on).
  *
  * \param int $interval
  *      (optional)-The interval at which log rotations happen.
  *      See also the documentation for the \a $when
  *      parameter for more information on how the two
  *      parameters interact with each other.
  *      The default for both this parameter and \a $when
  *      means that the log rotation will take place every hour.
  *
  * \param int $backupCount
  *      (optional) Specifies how many backup logs are kept
  *      alongside the current log file.
  *      Backup logs are named after the date and time
  *      at which they were created. The exact format
  *      depends on the value of the \a $when parameter.
  *      The default value is 0, which disables deletion
  *      of old backups.
  *
  * \param bool $delay
  *      (optional) Whether to delay the actual
  *      opening of the file until the first write.
  *      Defaults to \a false (no delay).
  *
  * \param bool $utc
  *      Whether the dates and times used in the backups'
  *      name should use UTC (\a true) or local time
  *      (\a false).
  */
 public function __construct($filename, $when = 'h', $interval = 1, $backupCount = 0, $delay = false, $utc = false)
 {
     parent::__construct($filename, 'a', $delay);
     $this->when = strtoupper($when);
     $this->backupCount = $backupCount;
     $this->utc = $utc;
     $this->rolloverAt = null;
     $this->dayOfWeek = null;
     if ($this->when == 'S') {
         $this->interval = 1;
         $this->suffix = '%Y-%m-%d_%H-%M-%S';
         $this->extMatch = '^\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}$';
     } elseif ($this->when == 'M') {
         $this->interval = 60;
         $this->suffix = '%Y-%m-%d_%H-%M';
         $this->extMatch = '^\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}$';
     } elseif ($this->when == 'H') {
         $this->interval = 60 * 60;
         $this->suffix = '%Y-%m-%d_%H';
         $this->extMatch = '^\\d{4}-\\d{2}-\\d{2}_\\d{2}$';
     } elseif ($this->when == 'D' || $this->when == 'MIDNIGHT') {
         $this->interval = 60 * 60 * 24;
         $this->suffix = '%Y-%m-%d';
         $this->extMatch = '^\\d{4}-\\d{2}-\\d{2}$';
     } elseif (substr($this->when, 0, 1) == 'W') {
         $this->interval = 60 * 60 * 24 * 7;
         if (strlen($this->when) != 2) {
             throw new \Plop\Exception(sprintf('You must specify a day for weekly rollover ' . 'from 0 to 6 (0 is Monday), not %s', $this->when));
         }
         $day = ord($this->when[1]) - ord('0');
         if ($day < 0 || $day > 6) {
             throw new \Plop\Exception(sprintf('Invalid day specified for weekly rollover: %s', $this->when[1]));
         }
         $this->dayOfWeek = $day;
         $this->suffix = '%Y-%m-%d';
         $this->extMatch = '^\\d{4}-\\d{2}-\\d{2}$';
     } else {
         throw new \Plop\Exception(sprintf('Invalid rollover interval specified: %s', $this->when));
     }
     if (!is_int($interval) || $interval < 1) {
         throw new \Plop\Exception('The interval should be an integer ' . 'greater than or equal to 1');
     }
     $this->interval = $this->interval * $interval;
     $this->rolloverAt = $this->computeRollover($this->getTime());
 }