added check for connected when triggered method is called. can't trigger
[urisagit/Stem.git] / Design / log_notes
CommitLineData
4536f655 1
2 Stem Logging Design
3
4The Stem logging subsystem is designed to be very flexible, powerful and
5yet simple to use. Log data comes into the system via a Log Entry which
6is submitted to Logical Logs. Entries can be submitted to multiple
7Logical Logs which can be local to the current Hub or on remote
8Hubs. Each Logical Log processes the Entry which can be filtered,
9redirected and written to physical log files. Logical Log filter rules
10can match the text or label with regular expressions, test the range or
11value of the level, check the time of day or do any boolean combination
12of those. If an Entry passes a set of rules, then it is passed to a set
13of actions which can execute a wide range of operations upon it
14including printing the entry to a file, sending it via email or to a
15pager, printing it to stderr, or the entry can be forwarded to other
16Logical Logs. The full set of filter rules and actions are described
17below.
18
19Log Entries are constructed with the 'new' method of the
20Stem::Log::Entry class. The caller can set the entry's text, label, and
21a severity level and the timestamp is automatically stored in the
22entry. If any Logical Logs are specified the entry is submitted to
23them. In any case, the entry object is returned and it can be submitted
24to Logical Logs with its submit method. The class Stem::Log::Entry is
25registered as a Cell so Log Entries that are forwarded from remote Hubs
26can be handled by this class. Log Entries can be created by created and
27submitted by code anywhere in Stem. Many Cells can be configured to
28submit Log Entries which contain data or status information. The
29Debug/Trace subsystem also generates Log Entries as do any monitoring
30modules such as Stem::LogTail.
31
32
33A Logical Log is constructed by the 'new' method of the Stem::Log
34class. They are typically created by external configurations but some
35modules create them internally for their own use. Each Logical Log on a
36Hub must have a unique name and that is the name used to submit Log
37Entries. Remote Logical Logs are referred to by a string of the form
38'Hub:LogName'. Any place where you can specify a Logical Log name, you
39can also use a remote Log name.
40
41When a Log Entry is submitted to a Logical Log it gets filtered and
42processed. The Logical Log is configured with optional physical file and
43filter attributes. If there is no filter in a Logical Log, its default
44is to print any submitted Entries to its file (if there is one). Logical
45Logs don't need to have a physical file attribute as they can filter and
46print their Entries to many other possible destinations (see below for a
47list of actions and Entry destinations).
48
49The 'path' attribute of a Logical Log specifies its file. Other
50attributes control the long term management of the file. They include
51when to rotate the log file, the format of the timestamp suffix of the
52rotated files, any compression to be performed, where to move archived
53logs, eternal programs to be called to process the log file, etc. These
54log file handling attributes and their code support are under development.
55
56The filter attribute of a Logical Log consists of a set of key/value
57pairs which are called filter operations. When an Entry is submitted to
58a Logical Log which has a filter, a private hash copy of all of its data
59is made and a special boolean called the filter flag is set in that
60hash. All of the filter operations are processed sequentially and work
61with that flag. The operations can be grouped into 3 types, flag
62operations, rules and actions. Flag operations directly modify the
63filter flag and its behavior which is used to control the rules and
64actions of this filter. Rules are boolean tests that check the submitted
65entry for some condition and can set or clear the filter flag. Actions
66print or forward the submitted Entry only if the filter flag is
67currently true. The filter flag is initialized to true so all actions
68and rules will be executed until some rule or flag operation clears it.
69
70Flag operations are always executed regardless of the current value of
71the filter flag. The current value of the filter flag can be set,
72cleared or inverted. Also the boolean operation that is used with the
73rules can be selected. It defaults to 'and' which causes each rule's
74boolean result to be 'and'ed with the filter flag and stored there. If
75the flag operator is set to 'or', then the rule result is or'ed with the
76flag and stored back into it. The boolean test of the filter flag can be
77inverted with the 'invert_test' flag operation. By combining the flag
78operations and the negated prefix of rules (see below) you can get any
79boolean combination of rules. If you want multiple sets of rules each
80with their own set of actions in a filter, just set the filter flag to
81true before each set of rules and follow them by their associated
82actions. If you want to execute some actions if any of a set of rules is
83true, set the filter flag to false, set the flag operation to 'or' and
84set the test to inverted. The next rules will execute since the test in
85inverted and the flags is false. If any rule returns true, it will will
86set the flag since it is 'or'ed with it. The rest of the rules will be
87skipped. Then the normal_test operation should be executed. The actions
88that follow will only be executed if any rule was true.
89
90Filter rules are only executed if the filter flag is currently true (or
91false when the inverted_flag operation is in effect). Each filter rule
92name can be prefixed with 'not_' which will invert the results of the
93rule. There are many builtin rules which are grouped into three
94categories. The first group matches either an Entry label or text with a
95regular expression. The second group compares the Entry severity level
96with an integer. The third group compares the Entry severity level with
97a global value in the %Stem::Vars::Env hash. Those hash values can
98be set on the command line, from environment variables and by code. This
99allows for fine control of how Entries get filtered by level. Examples
100of using that facility are to enable debug/trace calls to output to
101stderr or be forwarded to a remote Logical Log.
102
103Filter actions, like filter rules are only executed if the filter flag
104is currently true (or false when the inverted_flag operation is in
105effect). But actions cannot affect the value of the filter flag and are
106meant to send Log Entries to different destinations. The builtin actions
107can print Log Entries to stdout, stderr or the controlling TTY. Entries
108can be emailed, sent to a pager, written to the console with the wall or
109write commands, or forwarded to other Logical Logs. Of course they also
110can be written the to physical file associated with this Logical Log.
111
112WARNING: Currently forwarding loops can be created with Log filter
113actions. There are plans to detect them with either storing in the Log
114Entry a hop count or a history of which Logical Logs it has seen.
115
116Custom filter rules and actions can also be created. Any module can have
117them and they are called by their name which is the value of the
118'custom' operation. The difference between a custom rule and action is
119that the rules return a defined boolean value while the actions return
120the undefined value (a plain return does that).
121
122When a Log Entry needs to printed by an action (which all builtin ones
123except forwarding does), it must format the Entry. This is controlled by
124the 'format' attribute of the Logical Log. The format value is similar
125to sprintf and uses % as a field marker. It can print the Entry text
126(%T), label (%L), level (%l), timestamp (%l) and original Logical Log
127name (%N) (so forwarded Log Entries can say where they came from). The
128default Log Entry format is %T which will just print the text. Also the
129timestamp which is normally printed as an integer (Unix Epoch time) can
130be printed with the %f marker in a strftime format. The attribute which
131controls the time format is 'strftime'. The default strftime format is
132%C which will print the time as the command 'date' will.
133