1# This file was automatically generated by SWIG (http://www.swig.org).
2# Version 3.0.7
3#
4# Do not make changes to this file unless you know what you are doing--modify
5# the SWIG interface file instead.
6
7package Amanda::Debug;
8use base qw(Exporter);
9use base qw(DynaLoader);
10package Amanda::Debugc;
11bootstrap Amanda::Debug;
12package Amanda::Debug;
13@EXPORT = qw();
14
15# ---------- BASE METHODS -------------
16
17package Amanda::Debug;
18
19sub TIEHASH {
20    my ($classname,$obj) = @_;
21    return bless $obj, $classname;
22}
23
24sub CLEAR { }
25
26sub FIRSTKEY { }
27
28sub NEXTKEY { }
29
30sub FETCH {
31    my ($self,$field) = @_;
32    my $member_func = "swig_${field}_get";
33    $self->$member_func();
34}
35
36sub STORE {
37    my ($self,$field,$newval) = @_;
38    my $member_func = "swig_${field}_set";
39    $self->$member_func($newval);
40}
41
42sub this {
43    my $ptr = shift;
44    return tied(%$ptr);
45}
46
47
48# ------- FUNCTION WRAPPERS --------
49
50package 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
71package 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
84Amanda::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
95See C<debug.h> for a more in-depth description of the logging
96functionality of this module.
97
98=head1 DEBUG LOGGING
99
100Several debug logging functions, each taking a single string, are
101available:
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
119Perl's built-in C<die> and C<warn> functions are patched to call
120C<critical> and C<warning>, respectively.
121
122All of the debug logging functions are available via the export tag
123C<:logging>.
124
125Applications can adjust the handling of log messages with
126C<add_amanda_log_handler($hdlr)> where C<$hdlr> is a predefined log
127destination.  The following destinations are available in this
128package.  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
136Most applications should use L<Amanda::Util>'s C<setup_application> to
137initialize the debug libraries.  The initialization functions
138available from this module are thus considered "advanced", and the
139reader is advised to consult the C header, C<debug.h>, for details.
140
141Briefly, the functions C<dbopen> and C<dbrename> are used to open a
142debug file whose pathname includes all of the relevant
143information. C<dbclose> and C<dbreopen> are used to close that debug
144file before transferring control to another process.
145
146C<$error_exit_status> is the exit status with which C<critical> will
147exit.
148
149All of the initialization functions and variables are available via
150the export tag C<:init>.
151
152The current debug file's integer file descriptor (I<not> a Perl
153filehandle) is available from C<dbfd()>.  Likewise, C<dbfn()> returns
154the filename of the current debug file.
155
156C<debug_dup_stderr_to_debug()> redirects, at the file-descriptor
157level, C<STDERR> into the debug file.  This is useful when running
158external applications which may produce error output.
159
160=cut
161
162
163
164push @EXPORT_OK, qw(debug_init dbopen dbreopen dbrename dbclose
165    $error_exit_status);
166push @{$EXPORT_TAGS{"init"}}, qw(debug_init dbopen dbreopen dbrename dbclose
167    $error_exit_status);
168
169sub _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
186sub _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
195sub disable_die_override {
196    delete $SIG{__DIE__};
197    delete $SIG{__WARN__};
198}
199
200push @EXPORT_OK, qw(error critical warning message info debug);
201push @{$EXPORT_TAGS{"logging"}}, qw(error critical warning message info debug);
202
203push @EXPORT_OK, qw(add_amanda_log_handler
204    $amanda_log_stderr $amanda_log_syslog $amanda_log_null);
205push @{$EXPORT_TAGS{"logging"}}, qw(add_amanda_log_handler
206    $amanda_log_stderr $amanda_log_syslog $amanda_log_null);
2071;
208