1 | <?php |
---|
2 | /** |
---|
3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
4 | * contributor license agreements. See the NOTICE file distributed with |
---|
5 | * this work for additional information regarding copyright ownership. |
---|
6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
7 | * (the "License"); you may not use this file except in compliance with |
---|
8 | * the License. You may obtain a copy of the License at |
---|
9 | * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | * |
---|
12 | * Unless required by applicable law or agreed to in writing, software |
---|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | * See the License for the specific language governing permissions and |
---|
16 | * limitations under the License. |
---|
17 | * |
---|
18 | * |
---|
19 | * @package log4php |
---|
20 | * @subpackage appenders |
---|
21 | */ |
---|
22 | |
---|
23 | /** |
---|
24 | * @ignore |
---|
25 | */ |
---|
26 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); |
---|
27 | |
---|
28 | require_once(LOG4PHP_DIR . '/appenders/LoggerAppenderFile.php'); |
---|
29 | |
---|
30 | /** |
---|
31 | * LoggerAppenderDailyFile appends log events to a file ne. |
---|
32 | * |
---|
33 | * A formatted version of the date pattern is used as to create the file name |
---|
34 | * using the {@link PHP_MANUAL#sprintf} function. |
---|
35 | * <p>Parameters are {@link $datePattern}, {@link $file}. Note that file |
---|
36 | * parameter should include a '%s' identifier and should always be set |
---|
37 | * before {@link $file} param.</p> |
---|
38 | * |
---|
39 | * @author Abel Gonzalez <agonzalez@lpsz.org> |
---|
40 | * @author Knut Urdalen <knut.urdalen@gmail.com> |
---|
41 | * @version $Revision: 635069 $ |
---|
42 | * @package log4php |
---|
43 | * @subpackage appenders |
---|
44 | */ |
---|
45 | class LoggerAppenderDailyFile extends LoggerAppenderFile { |
---|
46 | |
---|
47 | /** |
---|
48 | * Format date. |
---|
49 | * It follows the {@link PHP_MANUAL#date()} formatting rules and <b>should always be set before {@link $file} param</b>. |
---|
50 | * @var string |
---|
51 | */ |
---|
52 | public $datePattern = "Ymd"; |
---|
53 | |
---|
54 | /** |
---|
55 | * Sets date format for the file name. |
---|
56 | * @param string $format a regular date() string format |
---|
57 | */ |
---|
58 | public function setDatePattern($format) { |
---|
59 | $this->datePattern = $format; |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * @return string returns date format for the filename |
---|
64 | */ |
---|
65 | public function getDatePattern() { |
---|
66 | return $this->datePattern; |
---|
67 | } |
---|
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 | public function setFile() { |
---|
76 | $numargs = func_num_args(); |
---|
77 | $args = func_get_args(); |
---|
78 | |
---|
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 | } |
---|
87 | |
---|