[LON-CAPA-cvs] cvs: loncom /metadata_database parse_activity_log.pl

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 20 Sep 2005 18:01:02 -0000


matthew		Tue Sep 20 14:01:02 2005 EDT

  Modified files:              
    /loncom/metadata_database	parse_activity_log.pl 
  Log:
  Use the same mechanism for logging chunks to store chunks from unparseable
  log lines.
  
  
Index: loncom/metadata_database/parse_activity_log.pl
diff -u loncom/metadata_database/parse_activity_log.pl:1.19 loncom/metadata_database/parse_activity_log.pl:1.20
--- loncom/metadata_database/parse_activity_log.pl:1.19	Tue Sep 20 13:49:51 2005
+++ loncom/metadata_database/parse_activity_log.pl	Tue Sep 20 14:01:01 2005
@@ -2,7 +2,7 @@
 #
 # The LearningOnline Network
 #
-# $Id: parse_activity_log.pl,v 1.19 2005/09/20 17:49:51 matthew Exp $
+# $Id: parse_activity_log.pl,v 1.20 2005/09/20 18:01:01 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -492,15 +492,10 @@
             if (length($chunk) > 20000) {
                 # avoid putting too much data into the database
                 # (usually an uploaded file or something similar)
-                $chunk = &escape($chunk);
-                if (! open(CHUNKFILE,">>$chunk_filename") ||
-                    ! print CHUNKFILE $timestamp.':'.$host.':'.$chunk.$/) {
-                    # abort
-                    close(CHUNKFILE);
+                if (! &savechunk(\$chunk,$timestamp,$host)) {
                     close(IN);
                     return undef;
                 }
-                close(CHUNKFILE);
                 next;
             }
             my $warningflag = '';
@@ -519,8 +514,12 @@
             if ($action !~ /^(LOGIN|VIEW|POST|CSTORE|STORE)$/) {
                 $warningflag .= 'action';
                 print $error_fh 'full log entry:'.$log.$/;
-                print $error_fh 'error on chunk:'.$chunk.$/;
-                $logthis->('(action) Unable to parse '.$/.$chunk.$/.
+                print $error_fh 'error on chunk (saving)'.$/;
+                if (! &savechunk(\$chunk,$timestamp,$host)) {
+                    close(IN);
+                    return undef;
+                }
+                $logthis->('(action) Unable to parse chunk'.$/.
                          'got '.
                          'time = '.$time.$/.
                          'res  = '.$res.$/.
@@ -557,6 +556,20 @@
     }
     close IN;
     return $linecount;
+    ##
+    ##
+    sub savechunk {
+        my ($chunkref,$timestamp,$host) = @_;
+        my $chunk = &escape(${$chunkref});
+        if (! open(CHUNKFILE,">>$chunk_filename") ||
+            ! print CHUNKFILE $timestamp.':'.$host.':'.$chunk.$/) {
+            # abort
+            close(CHUNKFILE);
+            return 0;
+        }
+        close(CHUNKFILE);
+        return 1;
+    }
 }