summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/cld/cld-logging.tex
blob: cbb904a6949d256e6b7027368ac0683257ad4c8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
% language=uk

% maybe this will become a section instead

\startcomponent cld-logging

\environment cld-environment

\startchapter[title={Logging}]

Logging and localized messages have always been rather standardized in \CONTEXT,
so upgrading the related mechanism had been quite doable. In \MKIV\ for a while
we had two systems in parallel: the old one, mostly targeted at messages at the
\TEX\ end, and a new one used at the \LUA\ end. But when more and more hybrid
code showed up, integrating both systems made sense.

Most logging concerns tracing and can be turned on and off on demand. This kind
of control is now possible for all messages. Given that the right interfaces are
used, you can turn off all messages:

\starttyping
context --silent
\stoptyping

This was already possible in \MKII, but there \TEX's own messages still were
visible. More important is that we have control:

\starttyping
context --silent=structure*,resolve*,font*
\stoptyping

This will disable all reporting for these three categories. It is also possible
to only disable messages to the console:

\starttyping
context --noconsole
\stoptyping

In \CONTEXT\ you can use directives:

\starttyping
\enabledirectives[logs.blocked=structure*,resolve*,font*]
\enabledirectives[logs.target=file]
\stoptyping

As all logging is under \LUA\ control and because this (and other) kind of
control has to kick in early in the initialization the code might look somewhat
tricky. Users won't notice this because they only deal with the formal interface.
Here we will only discuss the \LUA\ interfaces.

Messages related to tracing are done as follows:

\starttyping
local report_whatever = logs.reporter("modules","whatever")

report_whatever("not found: %s","this or that")
\stoptyping

The first line defined a logger in the category \type {modules}. You can give a
second argument as well, the subcategory. Both will be shown as part of the
message, of which an example is given in the second line.

These messages are shown directly, that is, when the function is called. However,
when you generate \TEX\ code, as we discuss in this document, you need to make
sure that the message is synchronized with that code. This can be done with a
messenger instead of a reporter.

\starttyping
local report_numbers = logs.reporter("numbers","check")
local status_numbers = logs.messenger("numbers","check")

status_numbers("number 1: %s, number 2: %s",123,456)
report_numbers("number 1: %s, number 2: %s",456,123)
\stoptyping

Both reporters and messages are localized when the pattern given as first
argument can be found in the \type {patterns} subtable of the interface messages.
Categories and subcategories are also translated, but these are looked up in the
\type {translations} subtable. So in the case of

\starttyping
report_whatever("found: %s",filename)
report_whatever("not found: %s",filename)
\stoptyping

you should not be surprised if it gets translated. Of course the category and
subcategory provide some contextual information.

\stopchapter

\stopcomponent