[system] / branches / gage_dev / webwork2 / lib / WeBWorK / Utils.pm Repository:
ViewVC logotype

Diff of /branches/gage_dev/webwork2/lib/WeBWorK/Utils.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 561 Revision 562
21our @EXPORT_OK = qw( 21our @EXPORT_OK = qw(
22 runtime_use 22 runtime_use
23 readFile 23 readFile
24 formatDateTime 24 formatDateTime
25 parseDateTime 25 parseDateTime
26 writeLog
27 writeTimingLogEntry
26 dbDecode 28 dbDecode
27 dbEncode 29 dbEncode
28 decodeAnswers 30 decodeAnswers
29 encodeAnswers 31 encodeAnswers
30 ref2string 32 ref2string
54 # %d numeric day of the month, with leading zeros (eg 01..31) 56 # %d numeric day of the month, with leading zeros (eg 01..31)
55 # %y year (2 digits) 57 # %y year (2 digits)
56 # %I hour, 12 hour clock, leading 0's) 58 # %I hour, 12 hour clock, leading 0's)
57 # %M minute, leading 0's 59 # %M minute, leading 0's
58 # %P am or pm (Yes %p and %P are backwards :) 60 # %P am or pm (Yes %p and %P are backwards :)
59 return time2str "%m/%d/%y %I:%M%P", $dateTime; 61 return time2str("%m/%d/%y %I:%M%P", $dateTime);
60} 62}
61 63
62sub parseDateTime($) { 64sub parseDateTime($) {
63 my $string = shift; 65 my $string = shift;
64 return str2time $string; 66 return str2time $string;
65} 67}
66 68
67#sub writeLog($$$) { 69sub writeLog($$@) {
68# my ($ce, $facility, $message) = @_; 70 my ($ce, $facility, @message) = @_;
69# die "There is no log file for $facility defined."
70# unless $ce->{webworkFiles}->{logs}->{$facility}; 71 unless ($ce->{webworkFiles}->{logs}->{$facility}) {
72 warn "There is no log file for the $facility facility defined.\n";
73 return;
74 }
71# my $logFile = $ce->{webworkFiles}->{logs}->{$facility}; 75 my $logFile = $ce->{webworkFiles}->{logs}->{$facility};
72# local *LOG; 76 local *LOG;
73# open LOG, "<<", $logFile 77 if (open LOG, ">>", $logFile) {
74# of die "failed to open $logFile for writing: $!"; 78 print LOG "[", time2str("%a %b %d %H:%M:%S %Y", time), "] @message\n";
75# print LOG $message;
76# close LOG; 79 close LOG;
77#} 80 } else {
81 warn "failed to open $logFile for writing: $!";
82 }
83}
84
85sub writeTimingLogEntry($$$$) {
86 my ($ce, $function, $details, $beginEnd) = @_;
87 return unless defined $ce->{webworkFiles}->{logs}->{timing};
88 $beginEnd = ($beginEnd eq "begin") ? ">" : "<";
89 writeLog($ce, "timing", "$$ ".time." $beginEnd $function [$details]");
90}
78 91
79# ----- 92# -----
80 93
81sub dbDecode($) { 94sub dbDecode($) {
82 my $string = shift; 95 my $string = shift;

Legend:
Removed from v.561  
changed lines
  Added in v.562

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9