Question
logFilename from
Twiki.cfg has
2026-02-02 expanded into the current year/month.
warningFilename and
debugFilename do not.
I came across this as our admin configured it that way be accident. It seems like a simple change to the
writeWarning and
writeDebug functions in
TWiki.pm.
Is it not a bad idea to?
Is there a good reason not to do this?
Here's a diff to make life easy
Category:
TWikiPatches
Diff is against the the
CairoRelease aka
TWikiRelease01Sep2004?
--- twiki/lib/TWiki.pm 2004-08-30 08:46:11.000000000 +0200
+++ new-twiki/lib/TWiki.pm 2004-09-07 16:08:42.000000000 +0200
@@ -242,25 +242,29 @@
sub writeWarning {
my( $text ) = @_;
if( $warningFilename ) {
my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime( time() );
my( $tmon) = $isoMonth[$mon];
$year = sprintf( "%.4u", $year + 1900 );
my $time = sprintf( "%.2u ${tmon} %.2u - %.2u:%.2u",
$mday, $year, $hour, $min );
- if( open( FILE, ">>$warningFilename" ) ) {
+ my $yearmonth = sprintf( "%.4u%.2u", $year, $mon+1 );
+ my $filename = $TWiki::warningFilename;
+ $filename =~ s/%DATE%/$yearmonth/go;
+
+ if( open( FILE, ">>$filename" ) ) {
print FILE "$time $text\n";
close( FILE );
} else {
- print STDERR "Couldn't write \"$text\" to $warningFilename: $!\n";
+ print STDERR "Couldn't write \"$text\" to $filename: $!\n";
}
}
}
=pod
---++ writeDebug( $text )
Prints date, time, and contents of $text to $debugFilename, typically
'debug.txt'. Use for debugging messages.
@@ -268,25 +272,29 @@
=cut
sub writeDebug {
my( $text ) = @_;
my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime( time() );
my( $tmon) = $isoMonth[$mon];
$year = sprintf( "%.4u", $year + 1900 );
my $time = sprintf( "%.2u ${tmon} %.2u - %.2u:%.2u", $mday, $year, $hour, $min );
- if( open( FILE, ">>$debugFilename" ) ) {
+ my $yearmonth = sprintf( "%.4u%.2u", $year, $mon+1 );
+ my $filename = $TWiki::debugFilename;
+ $filename =~ s/%DATE%/$yearmonth/go;
+
+ if( open( FILE, ">>$filename" ) ) {
print FILE "$time $text\n";
close( FILE );
} else {
- print STDERR "Couldn't write \"$text\" to $debugFilename: $!\n";
+ print STDERR "Couldn't write \"$text\" to $filename: $!\n";
}
}
=pod
---++ writeDebugTimes( $text )
Dumps user and system time spent, with deltas from last call, followed
by contents of $text, to debug log using writeDebug above. Use for
performance monitoring/debugging.
Environment
--
KevinBaker - 07 Sep 2004
Answer
I pasted this to
SupportDATEInAllLogFilenames, as a patch proposal, as I think it's a really good idea - though I would personally code it so there was a generic way of generating date-based filenames.
--
CrawfordCurrie - 10 Sep 2004