2 * Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
26 Amanda::Debug - support for debugging Amanda applications
30 use Amanda::Util qw( :constants );
32 Amanda::Util::setup_application("amcooltool", "server", $CONTEXT_CMDLINE);
34 debug("this is a debug message");
35 die("Unable to frobnicate the ergonator");
37 See C<debug.h> for a more in-depth description of the logging
38 functionality of this module.
42 Several debug logging functions, each taking a single string, are
47 =item C<error> - also aborts the program to produce a core dump
49 =item C<critical> - exits the program with C<$error_exit_status>
61 Perl's built-in C<die> and C<warn> functions are patched to call
62 C<critical> and C<warning>, respectively.
64 All of the debug logging functions are available via the export tag
67 Applications can adjust the handling of log messages with
68 C<add_amanda_log_handler($hdlr)> where C<$hdlr> is a predefined log
69 destination. The following destinations are available in this
70 package. See L<Amanda::Logfile> for C<$amanda_log_trace_log>.
78 Most applications should use L<Amanda::Util>'s C<setup_application> to
79 initialize the debug libraries. The initialization functions
80 available from this module are thus considered "advanced", and the
81 reader is advised to consult the C header, C<debug.h>, for details.
83 Briefly, the functions C<dbopen> and C<dbrename> are used to open a
84 debug file whose pathname includes all of the relevant
85 information. C<dbclose> and C<dbreopen> are used to close that debug
86 file before transferring control to another process.
88 C<$error_exit_status> is the exit status with which C<critical> will
91 All of the initialization functions and variables are available via
92 the export tag C<:init>.
94 The current debug file's integer file descriptor (I<not> a Perl
95 filehandle) is available from C<dbfd()>. Likewise, C<dbfn()> returns
96 the filename of the current debug file.
98 C<debug_dup_stderr_to_debug()> redirects, at the file-descriptor
99 level, C<STDERR> into the debug file. This is useful when running
100 external applications which may produce error output.