1
2[//000000001]: # (debug \- debug narrative)
3[//000000002]: # (Generated from file 'debug\.man' by tcllib/doctools with format 'markdown')
4[//000000003]: # (Copyright © 200?, Colin McCormack, Wub Server Utilities)
5[//000000004]: # (Copyright &copy; 2012\-2014, Andreas Kupries <andreas\_kupries@users\.sourceforge\.net>)
6[//000000005]: # (debug\(n\) 1\.0\.6 tcllib "debug narrative")
7
8<hr> [ <a href="../../../../toc.md">Main Table Of Contents</a> &#124; <a
9href="../../../toc.md">Table Of Contents</a> &#124; <a
10href="../../../../index.md">Keyword Index</a> &#124; <a
11href="../../../../toc0.md">Categories</a> &#124; <a
12href="../../../../toc1.md">Modules</a> &#124; <a
13href="../../../../toc2.md">Applications</a> ] <hr>
14
15# NAME
16
17debug \- debug narrative \- core
18
19# <a name='toc'></a>Table Of Contents
20
21  - [Table Of Contents](#toc)
22
23  - [Synopsis](#synopsis)
24
25  - [Description](#section1)
26
27  - [API](#section2)
28
29  - [Bugs, Ideas, Feedback](#section3)
30
31  - [Keywords](#keywords)
32
33  - [Category](#category)
34
35  - [Copyright](#copyright)
36
37# <a name='synopsis'></a>SYNOPSIS
38
39package require Tcl 8\.5
40package require debug ?1\.0\.6?
41
42[__debug\.____tag__ *message* ?*level*?](#1)
43[__debug__ __2array__](#2)
44[__debug__ __define__ *tag*](#3)
45[__debug__ __header__ *text*](#4)
46[__debug__ __level__ *tag* ?*level*? ?*fd*?](#5)
47[__debug__ __names__](#6)
48[__debug__ __off__ *tag*](#7)
49[__debug__ __on__ *tag*](#8)
50[__debug__ __parray__ *arrayvarname*](#9)
51[__debug__ __pdict__ *dict*](#10)
52[__debug__ __hexl__ *data* ?*prefix*?](#11)
53[__debug__ __nl__](#12)
54[__debug__ __tab__](#13)
55[__debug__ __prefix__ *tag* ?*text*?](#14)
56[__debug__ __setting__ \(*tag* *level*\) \.\.\. ?*fd*?](#15)
57[__debug__ __suffix__ *tag* ?*text*?](#16)
58[__debug__ __trailer__ *text*](#17)
59
60# <a name='description'></a>DESCRIPTION
61
62Debugging areas of interest are represented by 'tags' which have independently
63settable levels of interest \(an integer, higher is more detailed\)\.
64
65# <a name='section2'></a>API
66
67  - <a name='1'></a>__debug\.____tag__ *message* ?*level*?
68
69    For each known tag the package creates a command with this signature the
70    user can then use to provide the debug narrative of the tag\. The narrative
71    *message* is provided as a Tcl script whose value is
72    __[subst](\.\./\.\./\.\./\.\./index\.md\#subst)__ed in the caller's scope if
73    and only if the current level of interest for the *tag* matches or exceeds
74    the call's *level* of detail\. This is useful, as one can place arbitrarily
75    complex narrative in code without unnecessarily evaluating it\.
76
77    See methods __level__ and __setting__ for querying and manipulating
78    the current level of detail for tags\.
79
80    The actually printed text consists of not only the *message*, but also
81    global and tag\-specific prefix and suffix, should they exist, with each line
82    in the message having the specified headers and trailers\.
83
84    All these parts are __[subst](\.\./\.\./\.\./\.\./index\.md\#subst)__ableTcl
85    scripts, which are substituted once per message before assembly\.
86
87  - <a name='2'></a>__debug__ __2array__
88
89    This method returns a dictionary mapping the names of all debug tags
90    currently known to the package to their state and log level\. The latter are
91    encoded in a single numeric value, where a negative number indicates an
92    inactive tag at the level given by the absolute value, and a positive number
93    is an active tag at that level\.
94
95    See also method __settings__ below\.
96
97  - <a name='3'></a>__debug__ __define__ *tag*
98
99    This method registers the named *tag* with the package\. If the tag was not
100    known before it is placed in an inactive state\. The state of an already
101    known tag is left untouched\.
102
103    The result of the method is the empty string\.
104
105  - <a name='4'></a>__debug__ __header__ *text*
106
107    This method defines a global
108    __[subst](\.\./\.\./\.\./\.\./index\.md\#subst)__able Tcl script which
109    provides a text printed before each line of output\.
110
111    Note how this is tag\-independent\.
112
113    Further note that the header substitution happens only once per actual
114    printed message, i\.e\. all lines of the same message will have the same
115    actual heading text\.
116
117    The result of the method is the specified text\.
118
119  - <a name='5'></a>__debug__ __level__ *tag* ?*level*? ?*fd*?
120
121    This method sets the detail\-*level* for the *tag*, and the channel
122    *fd* to write the tags narration into\. The level is an integer value >= 0
123    defaulting to __1__\. The channel defaults to __stderr__\.
124
125    The result of the method is the new detail\-level for the tag\.
126
127  - <a name='6'></a>__debug__ __names__
128
129    This method returns a list containing the names of all debug tags currently
130    known to the package\.
131
132  - <a name='7'></a>__debug__ __off__ *tag*
133
134    This method registers the named *tag* with the package and sets it
135    inactive\.
136
137    The result of the method is the empty string\.
138
139  - <a name='8'></a>__debug__ __on__ *tag*
140
141    This method registers the named *tag* with the package, as active\.
142
143    The result of the method is the empty string\.
144
145  - <a name='9'></a>__debug__ __parray__ *arrayvarname*
146
147    This is a convenience method formatting the named array like the builtin
148    command __parray__, except it returns the resulting string instead of
149    writing it directly to __stdout__\.
150
151    This makes it suitable for use in debug messages\.
152
153  - <a name='10'></a>__debug__ __pdict__ *dict*
154
155    This is a convenience method formatting the dictionary similarly to how the
156    builtin command __parray__ does for array, and returns the resulting
157    string\.
158
159    This makes it suitable for use in debug messages\.
160
161  - <a name='11'></a>__debug__ __hexl__ *data* ?*prefix*?
162
163    This is a convenience method formatting arbitrary data into a hex\-dump and
164    returns the resulting string\.
165
166    This makes it suitable for use in debug messages\.
167
168    Each line of the dump is prefixed with *prefix*\. This prefix defaults to
169    the empty string\.
170
171  - <a name='12'></a>__debug__ __nl__
172
173    This is a convenience method to insert a linefeed character \(ASCII 0x0a\)
174    into a debug message\.
175
176  - <a name='13'></a>__debug__ __tab__
177
178    This is a convenience method to insert a TAB character \(ASCII 0x09\) into a
179    debug message\.
180
181  - <a name='14'></a>__debug__ __prefix__ *tag* ?*text*?
182
183    This method is similar to the method __header__ above, in that it
184    defines __[subst](\.\./\.\./\.\./\.\./index\.md\#subst)__able Tcl script which
185    provides more text for debug messages\.
186
187    In contrast to __header__ the generated text is added to the user's
188    message before it is split into lines, making it a per\-message extension\.
189
190    Furthermore the script is tag\-dependent\.
191
192    In exception to that, a script for tag __::__ is applied to all
193    messages\.
194
195    If both global and tag\-dependent prefix exist, both are applied, with the
196    global prefix coming before the tag\-dependent prefix\.
197
198    Note that the prefix substitution happens only once per actual printed
199    message\.
200
201    The result of the method is the empty string\.
202
203    If the *tag* was not known at the time of the call it is registered, and
204    set inactive\.
205
206  - <a name='15'></a>__debug__ __setting__ \(*tag* *level*\) \.\.\. ?*fd*?
207
208    This method is a multi\-tag variant of method __level__ above, with the
209    functionality of methods __on__, and __off__ also folded in\.
210
211    Each named *tag* is set to the detail\-*level* following it, with a
212    negative level deactivating the tag, and a positive level activating it\.
213
214    If the last argument is not followed by a level it is not treated as tag
215    name, but as the channel all the named tags should print their messages to\.
216
217    The result of the method is the empty string\.
218
219  - <a name='16'></a>__debug__ __suffix__ *tag* ?*text*?
220
221    This method is similar to the method __trailer__ below, in that it
222    defines __[subst](\.\./\.\./\.\./\.\./index\.md\#subst)__able Tcl script which
223    provides more text for debug messages\.
224
225    In contrast to __trailer__ the generated text is added to the user's
226    message before it is split into lines, making it a per\-message extension\.
227
228    Furthermore the script is tag\-dependent\.
229
230    In exception to that, a script for tag __::__ is applied to all
231    messages\.
232
233    If both global and tag\-dependent suffix exist, both are applied, with the
234    global suffix coming after the tag\-dependent suffix\.
235
236    Note that the suffix substitution happens only once per actual printed
237    message\.
238
239    The result of the method is the empty string\.
240
241    If the *tag* was not known at the time of the call it is registered, and
242    set inactive\.
243
244  - <a name='17'></a>__debug__ __trailer__ *text*
245
246    This method defines a global
247    __[subst](\.\./\.\./\.\./\.\./index\.md\#subst)__able Tcl script which
248    provides a text printed after each line of output \(before the EOL however\)\.
249
250    Note how this is tag\-independent\.
251
252    Further note that the trailer substitution happens only once per actual
253    printed message, i\.e\. all lines of the same message will have the same
254    actual trailing text\.
255
256    The result of the method is the specified text\.
257
258# <a name='section3'></a>Bugs, Ideas, Feedback
259
260This document, and the package it describes, will undoubtedly contain bugs and
261other problems\. Please report such in the category *debug* of the [Tcllib
262Trackers](http://core\.tcl\.tk/tcllib/reportlist)\. Please also report any ideas
263for enhancements you may have for either package and/or documentation\.
264
265When proposing code changes, please provide *unified diffs*, i\.e the output of
266__diff \-u__\.
267
268Note further that *attachments* are strongly preferred over inlined patches\.
269Attachments can be made by going to the __Edit__ form of the ticket
270immediately after its creation, and then using the left\-most button in the
271secondary navigation bar\.
272
273# <a name='keywords'></a>KEYWORDS
274
275[debug](\.\./\.\./\.\./\.\./index\.md\#debug), [log](\.\./\.\./\.\./\.\./index\.md\#log),
276[narrative](\.\./\.\./\.\./\.\./index\.md\#narrative),
277[trace](\.\./\.\./\.\./\.\./index\.md\#trace)
278
279# <a name='category'></a>CATEGORY
280
281debugging, tracing, and logging
282
283# <a name='copyright'></a>COPYRIGHT
284
285Copyright &copy; 200?, Colin McCormack, Wub Server Utilities
286Copyright &copy; 2012\-2014, Andreas Kupries <andreas\_kupries@users\.sourceforge\.net>
287