Tags:
create new tag
, view all tags
In VariableExpansionInWarningAndDebugFilename KevinBaker proposes:

logFilename from Twiki.cfg has 2017-09-04 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.


I would personally code it differently, so there was a single generic function for generating date-based filenames. But otherwise it's a really good idea.

-- CrawfordCurrie - 10 Sep 2004

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2005-02-18 - MattWilkie
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.