1Apache::TestTrace(3) User Contributed Perl Documentation Apache::TestTrace(3)
2
3
4
6 Apache::TestTrace - Helper output generation functions
7
9 use Apache::TestTrace;
10
11 debug "foo bar";
12
13 info_sub "missed it";
14
15 error_mark "something is wrong";
16
17 # test sub that exercises all the tracing functions
18 sub test {
19 print $Apache::TestTrace::LogFH
20 "TraceLevel: $Apache::TestTrace::Level\n";
21 $_->($_,[1..3],$_) for qw(emerg alert crit error
22 warning notice info debug todo);
23 print $Apache::TestTrace::LogFH "\n\n"
24 };
25
26 # demo the trace subs using default setting
27 test();
28
29 {
30 # override the default trace level with 'crit'
31 local $Apache::TestTrace::Level = 'crit';
32 # now only 'crit' and higher levels will do tracing lower level
33 test();
34 }
35
36 {
37 # set the trace level to 'debug'
38 local $Apache::TestTrace::Level = 'debug';
39 # now only 'debug' and higher levels will do tracing lower level
40 test();
41 }
42
43 {
44 open OUT, ">/tmp/foo" or die $!;
45 # override the default Log filehandle
46 local $Apache::TestTrace::LogFH = \*OUT;
47 # now the traces will go into a new filehandle
48 test();
49 close OUT;
50 }
51
52 # override tracing level via -trace opt
53 % t/TEST -trace=debug
54
55 # override tracing level via env var
56 % env APACHE_TEST_TRACE_LEVEL=debug t/TEST
57
59 This module exports a number of functions that make it easier generat‐
60 ing various diagnostics messages in your programs in a consistent way
61 and saves some keystrokes as it handles the new lines and sends the
62 messages to STDERR for you.
63
64 This module provides the same trace methods as syslog(3)'s log levels.
65 Listed from low level to high level: emerg(), alert(), crit(), error(),
66 warning(), notice(), info(), debug(). The only different function is
67 warning(), since warn is already taken by Perl.
68
69 The module provides another trace function called todo() which is use‐
70 ful for todo items. It has the same level as debug (the highest).
71
72 There are two more variants of each of these functions. If the _mark
73 suffix is appended (e.g., error_mark) the trace will start with the
74 filename and the line number the function was called from. If the _sub
75 suffix is appended (e.g., error_info) the trace will start with the
76 name of the subroutine the function was called from.
77
78 If you have "Term::ANSIColor" installed the diagnostic messages will be
79 colorized, otherwise a special for each function prefix will be used.
80
81 If "Data::Dumper" is installed and you pass a reference to a variable
82 to any of these functions, the variable will be dumped with
83 "Data::Dumper::Dumper()".
84
85 Functions whose level is above the level set in $Apache::Test‐
86 Trace::Level become NOPs. For example if the level is set to alert,
87 only alert() and emerg() functions will generate the output. The
88 default setting of this variable is warning. Other valid values are:
89 emerg, alert, crit, error, warning, notice, info, debug.
90
91 Another way to affect the trace level is to set
92 $ENV{APACHE_TEST_TRACE_LEVEL}, which takes effect if $Apache::Test‐
93 Trace::Level is not set. So an explicit setting of $Apache::Test‐
94 Trace::Level always takes precedence.
95
96 By default all the output generated by these functions goes to STDERR.
97 You can override the default filehandler by overriding $Apache::Test‐
98 Trace::LogFH with a new filehandler.
99
100 When you override this package's global variables, think about localiz‐
101 ing your local settings, so it won't affect other modules using this
102 module in the same run.
103
105 o provide an option to disable the coloring altogether via some flag
106 or import()
107
109 Stas Bekman with contributions from Doug MacEachern
110
111
112
113perl v5.8.8 2006-11-19 Apache::TestTrace(3)