ddb4d506838b7656675a617d18f5b9d69dfa0658
[debian/amanda] / perl / Amanda / Debug.pm
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 1.3.39
3 #
4 # Do not make changes to this file unless you know what you are doing--modify
5 # the SWIG interface file instead.
6
7 package Amanda::Debug;
8 use base qw(Exporter);
9 use base qw(DynaLoader);
10 package Amanda::Debugc;
11 bootstrap Amanda::Debug;
12 package Amanda::Debug;
13 @EXPORT = qw();
14
15 # ---------- BASE METHODS -------------
16
17 package Amanda::Debug;
18
19 sub TIEHASH {
20     my ($classname,$obj) = @_;
21     return bless $obj, $classname;
22 }
23
24 sub CLEAR { }
25
26 sub FIRSTKEY { }
27
28 sub NEXTKEY { }
29
30 sub FETCH {
31     my ($self,$field) = @_;
32     my $member_func = "swig_${field}_get";
33     $self->$member_func();
34 }
35
36 sub STORE {
37     my ($self,$field,$newval) = @_;
38     my $member_func = "swig_${field}_set";
39     $self->$member_func($newval);
40 }
41
42 sub this {
43     my $ptr = shift;
44     return tied(%$ptr);
45 }
46
47
48 # ------- FUNCTION WRAPPERS --------
49
50 package Amanda::Debug;
51
52 *debug_init = *Amanda::Debugc::debug_init;
53 *dbopen = *Amanda::Debugc::dbopen;
54 *dbreopen = *Amanda::Debugc::dbreopen;
55 *dbrename = *Amanda::Debugc::dbrename;
56 *dbclose = *Amanda::Debugc::dbclose;
57 *error = *Amanda::Debugc::error;
58 *critical = *Amanda::Debugc::critical;
59 *warning = *Amanda::Debugc::warning;
60 *message = *Amanda::Debugc::message;
61 *info = *Amanda::Debugc::info;
62 *debug = *Amanda::Debugc::debug;
63 *add_amanda_log_handler = *Amanda::Debugc::add_amanda_log_handler;
64 *suppress_error_traceback = *Amanda::Debugc::suppress_error_traceback;
65 *dbfd = *Amanda::Debugc::dbfd;
66 *dbfn = *Amanda::Debugc::dbfn;
67 *debug_dup_stderr_to_debug = *Amanda::Debugc::debug_dup_stderr_to_debug;
68
69 # ------- VARIABLE STUBS --------
70
71 package Amanda::Debug;
72
73 *error_exit_status = *Amanda::Debugc::error_exit_status;
74 *amanda_log_stderr = *Amanda::Debugc::amanda_log_stderr;
75 *amanda_log_syslog = *Amanda::Debugc::amanda_log_syslog;
76 *amanda_log_null = *Amanda::Debugc::amanda_log_null;
77
78 @EXPORT_OK = ();
79 %EXPORT_TAGS = ();
80
81
82 =head1 NAME
83
84 Amanda::Debug - support for debugging Amanda applications
85
86 =head1 SYNOPSIS
87
88   use Amanda::Util qw( :constants );
89
90   Amanda::Util::setup_application("amcooltool", "server", $CONTEXT_CMDLINE);
91
92   debug("this is a debug message");
93   die("Unable to frobnicate the ergonator");
94
95 See C<debug.h> for a more in-depth description of the logging
96 functionality of this module.
97
98 =head1 DEBUG LOGGING
99
100 Several debug logging functions, each taking a single string, are
101 available:
102
103 =over
104
105 =item C<error> - also aborts the program to produce a core dump
106
107 =item C<critical> - exits the program with C<$error_exit_status>
108
109 =item C<warning>
110
111 =item C<message>
112
113 =item C<info>
114
115 =item C<debug>
116
117 =back
118
119 Perl's built-in C<die> and C<warn> functions are patched to call
120 C<critical> and C<warning>, respectively.
121
122 All of the debug logging functions are available via the export tag
123 C<:logging>.
124
125 Applications can adjust the handling of log messages with
126 C<add_amanda_log_handler($hdlr)> where C<$hdlr> is a predefined log
127 destination.  The following destinations are available in this
128 package.  See L<Amanda::Logfile> for C<$amanda_log_trace_log>.
129
130   $amanda_log_null
131   $amanda_log_stderr
132   $amanda_log_syslog
133
134 =head1 ADVANCED USAGE
135
136 Most applications should use L<Amanda::Util>'s C<setup_application> to
137 initialize the debug libraries.  The initialization functions
138 available from this module are thus considered "advanced", and the
139 reader is advised to consult the C header, C<debug.h>, for details.
140
141 Briefly, the functions C<dbopen> and C<dbrename> are used to open a
142 debug file whose pathname includes all of the relevant
143 information. C<dbclose> and C<dbreopen> are used to close that debug
144 file before transferring control to another process.
145
146 C<$error_exit_status> is the exit status with which C<critical> will
147 exit.
148
149 All of the initialization functions and variables are available via
150 the export tag C<:init>.
151
152 The current debug file's integer file descriptor (I<not> a Perl
153 filehandle) is available from C<dbfd()>.  Likewise, C<dbfn()> returns
154 the filename of the current debug file.
155
156 C<debug_dup_stderr_to_debug()> redirects, at the file-descriptor
157 level, C<STDERR> into the debug file.  This is useful when running
158 external applications which may produce error output.
159
160 =cut
161
162
163
164 push @EXPORT_OK, qw(debug_init dbopen dbreopen dbrename dbclose
165     $error_exit_status);
166 push @{$EXPORT_TAGS{"init"}}, qw(debug_init dbopen dbreopen dbrename dbclose
167     $error_exit_status);
168
169 sub _my_die {
170     # $^S: (from perlvar)
171     #  undef -> parsing module/eval
172     #  1 -> executing an eval
173     #  0 -> otherwise
174     # we *only* want to call critical() in the "otherwise" case
175     if (!defined($^S) or $^S == 1) {
176         die(@_);
177     } else {
178         my ($msg) = @_;
179         chomp $msg;
180         suppress_error_traceback();
181         critical(@_);
182     }
183 };
184 $SIG{__DIE__} = \&_my_die;
185
186 sub _my_warn {
187     my ($msg) = @_;
188     chomp $msg;
189     warning(@_);
190 };
191 $SIG{__WARN__} = \&_my_warn;
192
193 # utility function for test scripts, which want to use the regular
194 # perl mechanisms
195 sub disable_die_override {
196     delete $SIG{__DIE__};
197     delete $SIG{__WARN__};
198 }
199
200 push @EXPORT_OK, qw(error critical warning message info debug);
201 push @{$EXPORT_TAGS{"logging"}}, qw(error critical warning message info debug);
202
203 push @EXPORT_OK, qw(add_amanda_log_handler
204     $amanda_log_stderr $amanda_log_syslog $amanda_log_null);
205 push @{$EXPORT_TAGS{"logging"}}, qw(add_amanda_log_handler
206     $amanda_log_stderr $amanda_log_syslog $amanda_log_null);
207 1;