.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Paranoid::Debug 3pm" .TH Paranoid::Debug 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Paranoid::Debug \- Trace message support for paranoid programs .SH VERSION .IX Header "VERSION" \&\f(CW$Id:\fR lib/Paranoid/Debug.pm, 2.10 2022/03/08 00:01:04 acorliss Exp $ .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Paranoid::Debug; \& \& PDEBUG = 1; \& PDMAXINDENT = 40; \& PDPREFIX = sub { scalar localtime }; \& pdebug("starting program", PDEBUG1); \& foo(); \& \& # New method \& sub foo { \& my $foo = shift; \& my @bar = shift; \& my $rv; \& \& subPreamble(PDEBUG1, \*(Aq$@\*(Aq, $foo, @bar); \& \& # Miscellaneous code... \& pdebug("someting happened!", PDEBUG2); \& \& # More miscellaneous code... \& \& subPostamble(PDEBUG1, \*(Aq$\*(Aq, $rv); \& \& return $rv; \& } \& \& # Old method \& sub foo { \& my $foo = shift; \& my @bar = shift; \& my $rv; \& \& pdebug(\*(Aqentering w/(%s)(%s)\*(Aq, PDEBUG1, $foo, @bar); \& pIn(); \& \& # Miscellaneous code... \& pdebug("someting happened!", PDEBUG2); \& \& # More miscellaneous code... \& \& pOut(); \& pdebug(\*(Aqleaving w/rv: %s\*(Aq, PDEBUG1, $rv); \& \& return $rv; \& } \& \& pderror("error msg"); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" The purpose of this module is to provide a useful framework to produce debugging output. With this module you can assign a level of detail to pdebug statements, and they'll only be displayed to STDERR when PDEBUG is set to that level or higher. This allows you to have your program produce varying levels of debugging output. .PP Using the \fBsubPreamble\fR and \fBsubPostamble\fR functions at the beginning and end of each function will cause debugging output to be indented appropriately so you can visually see the level of recursion. .PP \&\fBNOTE:\fR All modules within the Paranoid framework use this module. Their debug levels range from 9 and up. You should use 1 \- 8 for your own modules or code. PDEBUG1 \- PDEBUG8 exists for those purposes. .SH "IMPORT LISTS" .IX Header "IMPORT LISTS" This module exports the following symbols by default: .PP .Vb 1 \& PDEBUG pdebug pIn pOut subPreamble subPostamble PDEBUG1 .. PDEBUG8 .Ve .PP The following specialized import lists also exist: .PP .Vb 7 \& List Members \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& constants PDEBUG1 PDEBUG2 PDEBUG3 PDEBUG4 PDEBUG5 \& PDEBUG6 PDEBUG7 PDEBUG8 \& all @defaults @constants \& pderror PDPREFIX PDLEVEL1 PDLEVEL2 \& PDLEVEL3 PDLEVEL4 PDMAXINDENT .Ve .SH CONSTANTS .IX Header "CONSTANTS" .SS "PDEBUG1 .. PDEBUG8" .IX Subsection "PDEBUG1 .. PDEBUG8" There are eight constants exported by default for use by developers that allow for up to eight levels of diagnostic output. None of these levels are used by internal \fBParanoid\fR code, they are reserved for use by third parties. .SS "PDLEVEL1 .. PDLEVEL4" .IX Subsection "PDLEVEL1 .. PDLEVEL4" These constants are not intended for use by other modules, rather the exist for the internal debug levels used by all Paranoid::* modules. These levels are all higher than what PDEBUG* to allow the developer to have as much control over their verbosity as possible, but without the Paranoid diagnostics adding unwanted noise. .SH SUBROUTINES/METHODS .IX Header "SUBROUTINES/METHODS" .SS PDEBUG .IX Subsection "PDEBUG" \&\fBPDEBUG\fR is an lvalue subroutine which is initially set to 0, but can be set to any positive integer. The higher the number the more pdebug statements are printed. .SS PDPREFIX .IX Subsection "PDPREFIX" .Vb 1 \& PDPREFIX = sub { \& \& # Old default Prefix to use with debug messages looks like: \& # \& # [PID \- $dlevel] Subroutine: \& # \& my $caller = shift; \& my $indentation = shift; \& my $oi = $indentation; \& my $maxLevel = PDMAXINDENT; \& my $prefix; \& \& # Cap indentation \& $indentation = $maxLevel if $indentation > $maxLevel; \& \& # Construct the prefix \& $prefix = \*(Aq \*(Aq x $indentation . "[$$\-$oi] $caller: "; \& \& return $prefix; \& }; .Ve .PP \&\fBPDPREFIX\fR is an lvalue subroutine that contains a code reference to a subroutine that returns an appropriate prefix for debug messages. The default subroutine prints an indented string (indented according to depth on the call stack) that prints the process PID, debug level, and the current routine/or method that \fBpdebug\fR was called in. .SS PDMAXINDENT .IX Subsection "PDMAXINDENT" \&\fBPDMAXINDENT\fR is an lvalue subroutine which is initially set to 40, but can be set to any integer. This controls the max indentation of the debug messages. Obviously, it wouldn't help to indent a debug message by a hundred columns on an eighty column terminal just because your stack depth gets that deep. .SS pderror .IX Subsection "pderror" .Vb 1 \& pderror("error msg"); .Ve .PP This function prints the passed message to STDERR. .SS pdebug .IX Subsection "pdebug" .Vb 2 \& pdebug("debug statement", PDEBUG3); \& pdebug("debug statement: %s %2d %.3f", PDEBUG3, @values); .Ve .PP This function is called with one mandatory argument (the string to be printed), and an optional integer. This integer is compared against \fBPDEBUG\fR and the debug statement is printed if PDEBUG is equal to it or higher. .PP The return value is always the debug statement itself. This allows for a single statement to produce debug output and set variables. For instance: .PP .Vb 1 \& Paranoid::ERROR = pdebug("Something bad happened!", PDEBUG3); .Ve .PP As an added benefit you can pass a printf template along with their values and they will be handled appropriately. String values passed as \fBundef\fR will be replaced with the literal string "\fIundef\fR". .PP One deviation from printf allows you to specify a placeholder which can gobble up any number of extra arguments while still performing the "\fIundef\fR" substitution: .PP .Vb 1 \& pdebug("I was passed these values: %s", 3, @values); .Ve .SS pIn .IX Subsection "pIn" .Vb 1 \& pIn(); .Ve .PP This function causes all subsequent pdebug messages to be indented by one additional space. .SS pOut .IX Subsection "pOut" .Vb 1 \& pOut(); .Ve .PP This function causes all subsequent pdebug messages to be indented by one less space. .SS subPreamble .IX Subsection "subPreamble" .Vb 1 \& subPreamble(PDEBUG1, \*(Aq$@\*(Aq, @_); .Ve .PP This function combines the functionality of pdebug and pIn to mark the entry point into a given function. It also provides a convenient summarization function to prevent logging overly long arguments to diagnostic output. .PP The second argument to this function would be essentially whatever a valid subroutine prototype would be for your function (see \fIPrototypes\fR in \&\fBperlsub\fR\|(3) for more examples). In addition to the standard prototypes, we also support \fBp\fR as a prototype. This is essentially the same as a scalar prototype, but instead of printing a summarized excerpt of its contents, it replaces all characters with \fI*\fR characters. Any argument containing sensitive information, such as passwords, etc, should use \fBp\fR instead of \&\fB$\fR. .PP Summarization is performed in the following manner: any scalar value (excluding references of any kind) that exceeds 20 characters gets truncated to 20 characters, and appended with the full number of bytes. Lists merely report how many elements in the array, and hashes list the number if key/value pairs in the hash. All other types are passed as-is. .PP Indentation is adjusted after the initial summarized message. .SS subPostamble .IX Subsection "subPostamble" .Vb 1 \& subPostamble(PDEBUG1, \*(Aq$\*(Aq, $rv); .Ve .PP This function works the same as subPreamble, but with indentation happening in reverse order. The prototype should reflect the prototype of the returned value, not the function arguments. Indentation is set back prior to the the summarized message is printed. .SH DEPENDENCIES .IX Header "DEPENDENCIES" .IP o 4 .IX Item "o" Paranoid .IP o 4 .IX Item "o" Carp .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" \&\fBpderror\fR (and by extension, \fBpdebug\fR) will generate errors if STDERR is closed elsewhere in the program. .SH AUTHOR .IX Header "AUTHOR" Arthur Corliss (corliss@digitalmages.com) .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" This software is free software. Similar to Perl, you can redistribute it and/or modify it under the terms of either: .PP .Vb 7 \& a) the GNU General Public License \& as published by the \& Free Software Foundation ; either version 1 \& , or any later version \& , or \& b) the Artistic License 2.0 \& , .Ve .PP subject to the following additional term: No trademark rights to "Paranoid" have been or are conveyed under any of the above licenses. However, "Paranoid" may be used fairly to describe this unmodified software, in good faith, but not as a trademark. .PP (c) 2005 \- 2020, Arthur Corliss (corliss@digitalmages.com) (tm) 2008 \- 2020, Paranoid Inc. (www.paranoid.com)