1Apache::TestTrace(3)  User Contributed Perl Documentation Apache::TestTrace(3)
2
3
4

NAME

6       Apache::TestTrace - Helper output generation functions
7

SYNOPSIS

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

DESCRIPTION

59       This module exports a number of functions that make it easier
60       generating various diagnostics messages in your programs in a
61       consistent way and saves some keystrokes as it handles the new lines
62       and sends the 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
70       useful 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
86       $Apache::TestTrace::Level become NOPs. For example if the level is set
87       to alert, only alert() and emerg() functions will generate the output.
88       The default setting of this variable is warning. Other valid values
89       are: 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
93       $Apache::TestTrace::Level is not set. So an explicit setting of
94       $Apache::TestTrace::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
98       $Apache::TestTrace::LogFH with a new filehandler.
99
100       When you override this package's global variables, think about
101       localizing your local settings, so it won't affect other modules using
102       this module in the same run.
103

TODO

105        o provide an option to disable the coloring altogether via some flag
106          or import()
107

AUTHOR

109       Stas Bekman with contributions from Doug MacEachern
110
111
112
113perl v5.34.0                      2022-02-02              Apache::TestTrace(3)
Impressum