From ae0bdcfb6b4938fbe8c41cd70bc10bb184d130b4 Mon Sep 17 00:00:00 2001 From: eldy <> Date: Wed, 28 Nov 2001 01:30:39 +0000 Subject: [PATCH] Add various tags to use dynamic log file name in conf file according to current but also older date/time (%YYYY-n, %YY-n, %MM-n, %DD-n, %HH-n) --- wwwroot/cgi-bin/awstats.model.conf | 23 +++++++++++++++-------- wwwroot/cgi-bin/awstats.pl | 29 +++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/wwwroot/cgi-bin/awstats.model.conf b/wwwroot/cgi-bin/awstats.model.conf index 88a27557..b90901af 100644 --- a/wwwroot/cgi-bin/awstats.model.conf +++ b/wwwroot/cgi-bin/awstats.model.conf @@ -13,16 +13,23 @@ # MAIN SETUP SECTION (Required to make AWStats working) #------------------------------------------------------------------------ -# "LogFile" contains the web server logfile name to analyze. -# You can use a full path... +# "LogFile" contains the web server logfile to analyze. +# You can use a full path or relative path from awstats.pl directory. # Example: "/var/log/apache/access.log" -# or relative path from awstats.pl directory... # Example: "../logs/mycombinedlog.log" # -# You can also use %YY %MM %DD %HH or %WM in file name, AWStats will -# replace those tags with current year month day hour or -# week of month. -# Example: "C:/WINNT/system32/LogFiles/W3SVC1/ex%YY%MM%DD.log" +# You can also use tags in this filename if you need a dynamic file name +# depending on date or time (Replacement is made by AWStats at the beginning +# of its execution). This is available tags : +# %YYYY-n is replaced with 4 digits year we were n hours ago +# %YY-n is replaced with 2 digits year we were n hours ago +# %MM-n is replaced with month we were n hours ago +# %DD-n is replaced with day we were n hours ago +# %HH-n is replaced with hour we were n hours ago +# %WM-n is replaced with the week number in month (1-5) +# You can use n=0 if you need current year, month, day, hour... +# Example: "/var/log/access_log.%YYYY-24%MM-24%DD-24.log" +# Example: "C:/WINNT/system32/LogFiles/W3SVC1/ex%YY-0%MM-0%DD-0.log" # LogFile="/var/log/httpd/mylog.log" @@ -189,7 +196,7 @@ ArchiveLogRecords=0 KeepBackupOfHistoricFiles=0 # Set your primary language. -# Possible value: +# Possible value: # Bosnian=ba, Chinese (Taiwan)=tw, Chinese (Traditional)=cn, Czech=cz, # Danish=dk, Dutch=nl, English=en, French=fr, German=de, Greek=gr, # Hungarian=hu, Indonesian=id, Italian=it, Japanese=jp, Korean=kr, diff --git a/wwwroot/cgi-bin/awstats.pl b/wwwroot/cgi-bin/awstats.pl index a1bf0cdd..c55106c8 100644 --- a/wwwroot/cgi-bin/awstats.pl +++ b/wwwroot/cgi-bin/awstats.pl @@ -82,7 +82,7 @@ $WarningMessages= 1; %MonthBytes = %MonthHits = %MonthHostsKnown = %MonthHostsUnknown = %MonthPages = %MonthUnique = %MonthVisits = %monthlib = %monthnum = (); -$VERSION="3.2 (build 65)"; +$VERSION="3.2 (build 66)"; $Lang="en"; # Default value @@ -424,13 +424,38 @@ sub Read_Config_File { # Read main section if ($param =~ /^LogFile/) { $LogFile=$value; - # Replace %YYYY %YY %MM %DD %HH with current value + if ($LogFile =~ /%([YMDH]+)-(\d*)/) { + my $timephase=$2; + debug(" Found a time phase of $timephase hour in log file name",1); + # Get older time + ($oldersec,$oldermin,$olderhour,$olderday,$oldermonth,$olderyear,$olderwday) = localtime($nowtime-($timephase*3600)); + $olderweekofmonth=int($olderday/7); + $olderdaymod=$olderday%7; + $olderwday++; + if ($olderdaymod <= $olderwday) { if (($olderwday != 7) || ($olderdaymod != 0)) { $olderweekofmonth=$olderweekofmonth+1; } } + if ($olderdaymod > $olderwday) { $olderweekofmonth=$olderweekofmonth+2; } + if ($olderyear < 100) { $olderyear+=2000; } else { $olderyear+=1900; } + $oldersmallyear=$olderyear;$oldersmallyear =~ s/^..//; + if (++$oldermonth < 10) { $oldermonth = "0$oldermonth"; } + if ($olderday < 10) { $olderday = "0$olderday"; } + if ($olderhour < 10) { $olderhour = "0$olderhour"; } + if ($oldermin < 10) { $oldermin = "0$oldermin"; } + if ($oldersec < 10) { $oldersec = "0$oldersec"; } + $LogFile =~ s/%YYYY-$timephase/$olderyear/g; + $LogFile =~ s/%YY-$timephase/$oldersmallyear/g; + $LogFile =~ s/%MM-$timephase/$oldermonth/g; + $LogFile =~ s/%DD-$timephase/$olderday/g; + $LogFile =~ s/%HH-$timephase/$olderhour/g; + $LogFile =~ s/%WM-$timephase/$olderweekofmonth/g; + } + # Replace %YYYY %YY %MM %DD %HH with current value. Kept for backward compatibility. $LogFile =~ s/%YYYY/$nowyear/g; $LogFile =~ s/%YY/$nowsmallyear/g; $LogFile =~ s/%MM/$nowmonth/g; $LogFile =~ s/%DD/$nowday/g; $LogFile =~ s/%HH/$nowhour/g; $LogFile =~ s/%WM/$nowweekofmonth/g; + debug(" LogFile=$LogFile",1); next; } if ($param =~ /^LogFormat/) { $LogFormat=$value; next; } -- 2.47.3