-
Notifications
You must be signed in to change notification settings - Fork 1
/
errlog-split-yrmt.awk
41 lines (38 loc) · 1.02 KB
/
errlog-split-yrmt.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Split Apache HTTPD erorr log by year and month
# Written by Georgi D. Sotirov <[email protected]>
#
# Error log format is defined by ErrorLogFormat directive
# (see https://httpd.apache.org/docs/2.4/mod/core.html#errorlogformat),
# which by default is
# [%t] [%l] [pid %P] %F: %E: [client %a] %M"
# where %t is the timestamp formatted as
# [DDD MMM DD HH:MM:SS.FFFFFF YYYY]
# so it's necessary to get 2nd field separated by square brackets.
# Then year is 5th and month is 2nd field separated by space (or
# in some cases multiple spaces).
#
BEGIN {
FS="[][]"
months["Jan"] = 1
months["Feb"] = 2
months["Mar"] = 3
months["Apr"] = 4
months["May"] = 5
months["Jun"] = 6
months["Jul"] = 7
months["Aug"] = 8
months["Sep"] = 9
months["Oct"] = 10
months["Nov"] = 11
months["Dec"] = 12
}
{
split($2, dat, " *");
if ( FILENAME == "-" )
LOG_FNAME = "error_log"
else
LOG_FNAME = FILENAME
if ( dat[5] != 0 && dat[2] != 0 )
fn = sprintf("%s-%d%02d", LOG_FNAME, dat[5], months[dat[2]])
print > fn
}