1DateFormat(3)         User Contributed Perl Documentation        DateFormat(3)
2
3
4

NAME

6       Log::Log4perl::DateFormat - Log4perl advanced date formatter helper
7       class
8

SYNOPSIS

10           use Log::Log4perl::DateFormat;
11
12           my $format = Log::Log4perl::DateFormat->new("HH:mm:ss,SSS");
13
14           # Simple time, resolution in seconds
15           my $time = time();
16           print $format->format($time), "\n";
17               # => "17:02:39,000"
18
19           # Advanced time, resultion in milliseconds
20           use Time::HiRes;
21           my ($secs, $msecs) = Time::HiRes::gettimeofday();
22           print $format->format($secs, $msecs), "\n";
23               # => "17:02:39,959"
24

DESCRIPTION

26       "Log::Log4perl::DateFormat" is a low-level helper class for the
27       advanced date formatting functions in "Log::Log4perl::Layout::Pattern‐
28       Layout".
29
30       Unless you're writing your own Layout class like Log::Log4perl::Lay‐
31       out::PatternLayout, there's probably not much use for you to read this.
32
33       "Log::Log4perl::DateFormat" is a formatter which allows dates to be
34       formatted according to the log4j spec on
35
36           http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html
37
38       which allows the following placeholders to be recognized and processed:
39
40           Symbol Meaning              Presentation    Example
41           ------ -------              ------------    -------
42           G      era designator       (Text)          AD
43           y      year                 (Number)        1996
44           M      month in year        (Text & Number) July & 07
45           d      day in month         (Number)        10
46           h      hour in am/pm (1~12) (Number)        12
47           H      hour in day (0~23)   (Number)        0
48           m      minute in hour       (Number)        30
49           s      second in minute     (Number)        55
50           S      millisecond          (Number)        978
51           E      day in week          (Text)          Tuesday
52           D      day in year          (Number)        189
53           F      day of week in month (Number)        2 (2nd Wed in July)
54           w      week in year         (Number)        27
55           W      week in month        (Number)        2
56           a      am/pm marker         (Text)          PM
57           k      hour in day (1~24)   (Number)        24
58           K      hour in am/pm (0~11) (Number)        0
59           z      time zone            (Text)          Pacific Standard Time
60           Z      RFC 822 time zone    (Text)          -0800
61           '      escape for text      (Delimiter)
62           ''     single quote         (Literal)       '
63
64       For example, if you want to format the current Unix time in "MM/dd
65       HH:mm" format, all you have to do is this:
66
67           use Log::Log4perl::DateFormat;
68
69           my $format = Log::Log4perl::DateFormat->new("MM/dd HH:mm");
70
71           my $time = time();
72           print $format->format($time), "\n";
73
74       While the "new()" method is expensive, because it parses the format
75       strings and sets up all kinds of structures behind the scenes, followup
76       calls to "format()" are fast, because "DateFormat" will just call
77       "localtime()" and "sprintf()" once to return the formatted date/time
78       string.
79
80       So, typically, you would initialize the formatter once and then reuse
81       it over and over again to display all kinds of time values.
82
83       Also, for your convenience, the following predefined formats are avail‐
84       able, just as outlined in the log4j spec:
85
86           Format   Equivalent                     Example
87           ABSOLUTE "HH:mm:ss,SSS"                 "15:49:37,459"
88           DATE     "dd MMM yyyy HH:mm:ss,SSS"     "06 Nov 1994 15:49:37,459"
89           ISO8601  "yyyy-MM-dd HH:mm:ss,SSS"      "1999-11-27 15:49:37,459"
90           APACHE   "[EEE MMM dd HH:mm:ss yyyy]"   "[Wed Mar 16 15:49:37 2005]"
91
92       So, instead of passing
93
94           Log::Log4perl::DateFormat->new("HH:mm:ss,SSS");
95
96       you could just as well say
97
98           Log::Log4perl::DateFormat->new("ABSOLUTE");
99
100       and get the same result later on.
101
102       Known Shortcomings
103
104       The following placeholders are currently not recognized, unless someone
105       (and that could be you :) implements them:
106
107           F day of week in month
108           w week in year
109           W week in month
110           k hour in day
111           K hour in am/pm
112           z timezone (but we got 'Z' for the numeric time zone value)
113
114       Also, "Log::Log4perl::DateFormat" just knows about English week and
115       month names, internationalization support has to be added.
116

SEE ALSO

AUTHOR

119           Mike Schilli, <log4perl@perlmeister.com>
120
121
122
123perl v5.8.8                       2002-07-10                     DateFormat(3)
Impressum