| … | |
… | |
| 21 | our @EXPORT_OK = qw( |
21 | our @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 | |
| 62 | sub parseDateTime($) { |
64 | sub parseDateTime($) { |
| 63 | my $string = shift; |
65 | my $string = shift; |
| 64 | return str2time $string; |
66 | return str2time $string; |
| 65 | } |
67 | } |
| 66 | |
68 | |
| 67 | #sub writeLog($$$) { |
69 | sub 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 | |
|
|
85 | sub 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 | |
| 81 | sub dbDecode($) { |
94 | sub dbDecode($) { |
| 82 | my $string = shift; |
95 | my $string = shift; |