From: jj v. a. <we...@ma...> - 2005-08-28 20:54:03
|
Log Message: ----------- Allow use of an activity log which logs every click, stored on a per-course basis. It is turned off by default. It can be turned on/off for individual courses. The three pieces here: global.conf.dist: adds a place to define the log file. Here an empty value signals to not do this logging. ContentGenerator.pm: check to see if the log file is defined (and (non-trivial), and if so, write a log entry. We check if it is defined at this point to both save some time, and because if we get to writeCourseLog and the log isn't defined, we get a pink screen. The bulk of the text of the log entry is performed by a new method prepare_activity_entry. By default, this gives the url, and a list of all the cgi parameters (except for key and passwd). This method can be overridden by individual modules. The default format may change. It may take some fine tuning to see what is best. Also, this is one of the first functions called by go. We may want it to go after the action has taken place if we want instructor modules to be able to report results of their work through this log. SetMaker.pm: gives an example of overriding prepare_activity_entry. SetMaker has lots (and lots and lots) of data stored in cgi parameters. We probably don't want to log that. We might want to log a little more in SetMaker than we do here (target set), but this gives a start. Modified Files: -------------- webwork-modperl/conf: global.conf.dist webwork-modperl/lib/WeBWorK: ContentGenerator.pm webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor: SetMaker.pm Revision Data ------------- Index: global.conf.dist =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/conf/global.conf.dist,v retrieving revision 1.133 retrieving revision 1.134 diff -Lconf/global.conf.dist -Lconf/global.conf.dist -u -r1.133 -r1.134 --- conf/global.conf.dist +++ conf/global.conf.dist @@ -411,6 +411,12 @@ # Log logins. $courseFiles{logs}{login_log} = "$courseDirs{logs}/login.log"; +# Log for almost every click. By default it is the empty string, which +# turns this log off. If you want it turned on, we suggest +# "$courseDirs{logs}/activity.log" +# When turned on, this log can get quite large. +$courseFiles{logs}{activity_log} = ''; + ################################################################################ # Site defaults (FIXME: what other things could be "site defaults"?) ################################################################################ Index: ContentGenerator.pm =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/lib/WeBWorK/ContentGenerator.pm,v retrieving revision 1.147 retrieving revision 1.148 diff -Llib/WeBWorK/ContentGenerator.pm -Llib/WeBWorK/ContentGenerator.pm -u -r1.147 -r1.148 --- lib/WeBWorK/ContentGenerator.pm +++ lib/WeBWorK/ContentGenerator.pm @@ -144,6 +144,14 @@ my $returnValue = OK; + # We only write to the activity log if it has been defined and if + # we are in a specific course. The latter check is to prevent attempts + # to write to a course log file when viewing the top-level list of + # courses page. + WeBWorK::Utils::writeCourseLog($ce, 'activity_log', + $self->prepare_activity_entry) if ( $r->urlpath->arg("courseID") and + $r->ce->{courseFiles}->{logs}->{activity_log}); + $self->pre_header_initialize(@_) if $self->can("pre_header_initialize"); # send a file instead of a normal reply (reply_with_file() sets this field) @@ -329,6 +337,23 @@ $self->addmessage(CGI::div({class=>"ResultsWithError"}, $message)); } +=item prepare_activity_entry() + +Prepare a string to be sent to the activity log, if it is turned on. +This can be overriden by different modules. + +=cut + + +sub prepare_activity_entry { + my $self = shift; + my $r = $self->r; + my $string = $r->urlpath->path . " ---> ". + join("\t", (map { $_ eq 'key' || $_ eq 'passwd' ? '' : $_ ." => " . $r->param($_) } $r->param())); + $string =~ s/\t+/\t/g; + return($string); +} + =back =cut Index: SetMaker.pm =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v retrieving revision 1.53 retrieving revision 1.54 diff -Llib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm -Llib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm -u -r1.53 -r1.54 --- lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm +++ lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm @@ -71,6 +71,13 @@ 'headers' => 1, 'macros' => 1, 'email' => 1, ); +sub prepare_activity_entry { + my $self=shift; + my $r = $self->r; + my $user = $self->r->param('user') || 'NO_USER'; + return("In SetMaker as user $user"); +} + ## This is for searching the disk for directories containing pg files. ## to make the recursion work, this returns an array where the first ## item is the number of pg files in the directory. The second is a |