| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/Debug.pm,v 1.3 2004/10/06 21:01:17 gage Exp $ |
4 | # $CVSHeader: webwork2/lib/WeBWorK/Debug.pm,v 1.4 2004/10/08 18:30:32 jj Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 38 | |
38 | |
| 39 | =cut |
39 | =cut |
| 40 | |
40 | |
| 41 | use strict; |
41 | use strict; |
| 42 | use warnings; |
42 | use warnings; |
|
|
43 | use Time::HiRes qw/gettimeofday/; |
| 43 | |
44 | |
| 44 | ################################################################################ |
45 | ################################################################################ |
| 45 | |
46 | |
| 46 | =head1 CONFIGURATION VARIABLES |
47 | =head1 CONFIGURATION VARIABLES |
| 47 | |
48 | |
| … | |
… | |
| 63 | |
64 | |
| 64 | our $Logfile = "" unless defined $Logfile; |
65 | our $Logfile = "" unless defined $Logfile; |
| 65 | |
66 | |
| 66 | =item $QuellSubroutineOutput |
67 | =item $QuellSubroutineOutput |
| 67 | |
68 | |
| 68 | Prevent subroutines matching the following regular expression from logging. |
69 | If defined, prevent subroutines matching the following regular expression from |
|
|
70 | logging. |
| 69 | |
71 | |
| 70 | =cut |
72 | =cut |
| 71 | |
73 | |
| 72 | our $QuellSubroutineOutput; |
74 | our $QuellSubroutineOutput; |
|
|
75 | |
|
|
76 | =item $AllowSubroutineOutput |
|
|
77 | |
|
|
78 | If defined, allow only subroutines matching the following regular expression to |
|
|
79 | log. |
|
|
80 | |
|
|
81 | =cut |
|
|
82 | |
|
|
83 | our $AllowSubroutineOutput; |
| 73 | |
84 | |
| 74 | =back |
85 | =back |
| 75 | |
86 | |
| 76 | =cut |
87 | =cut |
| 77 | |
88 | |
| … | |
… | |
| 90 | sub debug { |
101 | sub debug { |
| 91 | my (@message) = @_; |
102 | my (@message) = @_; |
| 92 | |
103 | |
| 93 | if ($Enabled) { |
104 | if ($Enabled) { |
| 94 | my ($package, $filename, $line, $subroutine) = caller(1); |
105 | my ($package, $filename, $line, $subroutine) = caller(1); |
|
|
106 | return if defined $AllowSubroutineOutput and not $subroutine =~ m/$AllowSubroutineOutput/; |
| 95 | return if defined $QuellSubroutineOutput and $subroutine =~ m/$QuellSubroutineOutput/; |
107 | return if defined $QuellSubroutineOutput and $subroutine =~ m/$QuellSubroutineOutput/; |
| 96 | |
108 | |
|
|
109 | my ($sec, $msec) = gettimeofday; |
|
|
110 | my $date = time2str("%a %b %d %H:%M:%S.$msec %Y", $sec); |
| 97 | my $finalMessage = "$subroutine: " . join("", @message); |
111 | my $finalMessage = "[$date] $subroutine: " . join("", @message); |
| 98 | $finalMessage .= "\n" unless $finalMessage =~ m/\n$/; |
112 | $finalMessage .= "\n" unless $finalMessage =~ m/\n$/; |
| 99 | $finalMessage = "[" . time2str("%a %b %d %H:%M:%S %Y", time) . "] " .$finalMessage; |
113 | |
| 100 | if ($WeBWorK::Debug::Logfile ne "") { |
114 | if ($WeBWorK::Debug::Logfile ne "") { |
| 101 | if (open my $fh, ">>", $Logfile) { |
115 | if (open my $fh, ">>", $Logfile) { |
| 102 | print $fh $finalMessage; |
116 | print $fh $finalMessage; |
| 103 | close $fh; |
117 | close $fh; |
| 104 | } else { |
118 | } else { |