Rev 1209 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1207 | daniel-mar | 1 | |
1267 | daniel-mar | 2 | OIDplus Logger Mask Codes |
3 | ========================= |
||
1207 | daniel-mar | 4 | |
1267 | daniel-mar | 5 | ## What is a mask code? |
1207 | daniel-mar | 6 | |
7 | A "mask code" gives information about the log event. |
||
8 | It contains: |
||
9 | 1. The severity (info, warning, error, critical) |
||
10 | 2. In which logbook(s) the event shall be placed |
||
11 | |||
12 | Example: |
||
13 | Let's imagine the following event: |
||
14 | |||
15 | "Person 'X' moves from house 'A' to house 'B'" |
||
16 | |||
17 | This event would affect: |
||
18 | - Person 'X' |
||
19 | - House 'A' |
||
20 | - House 'B' |
||
21 | |||
22 | Instead of logging into 3 logbooks separately, you would create a mask code that tells the system to put the message |
||
23 | into the logbooks of person X, house A, and house B. |
||
24 | |||
1267 | daniel-mar | 25 | ## Syntax rules |
1207 | daniel-mar | 26 | |
27 | In the code, mask codes would look like this: |
||
28 | |||
1267 | daniel-mar | 29 | OIDplus::logger()->log("V2:[INFO]OID(%1)", "RA of object '%1' changed from '%2' to '%3'", $oid, $old_ra, $new_ra); |
1207 | daniel-mar | 30 | |
1267 | daniel-mar | 31 | As you can see, the mask code and message can be parameterized like `sprintf()` does, |
1207 | daniel-mar | 32 | but with the difference that `%1`, `%2`, `%3`, ..., is used instead of `%s`. |
33 | |||
1267 | daniel-mar | 34 | Please note that the event message is not enclosed in `_L(...)`, |
35 | because log messages are always written in English, |
||
1207 | daniel-mar | 36 | and not in the front-end language of the user. |
37 | |||
1267 | daniel-mar | 38 | ### Version |
39 | |||
40 | A mask code begins with `V2:` |
||
41 | |||
42 | ### Components |
||
43 | |||
44 | A mask code can have multiple components which are split into single codes using `+` or `/`, e.g. `OID(x)+RA(x)` would |
||
45 | be split to `OID(x)` and `RA(x)` which would result in the message being placed in the logbook of OID x, |
||
46 | and the logbook of the RA owning OID x. |
||
47 | |||
48 | ### Severity |
||
49 | |||
1207 | daniel-mar | 50 | At the beginning of each mask code, you must define a severity, which is written in square brackets. |
1267 | daniel-mar | 51 | |
1207 | daniel-mar | 52 | Valid severities: |
53 | - `[OK]`: Rule of thumb: YOU have done something and it was successful. |
||
54 | - `[INFO]`: Rule of thumb: Someone else has done something (that affects you) and it was successful. |
||
55 | - `[WARN]`: Rule of thumb: Something happened (probably someone did something) and it affects you. |
||
56 | - `[ERR]`: Rule of thumb: Something failed (probably someone did something) and it affects you. |
||
57 | - `[CRIT]`: Rule of thumb: Something happened (probably someone did something) which is not an error, but some critical situation (e.g. hardware failure), and it affects you. |
||
58 | |||
1267 | daniel-mar | 59 | If you have a mask code with multiple components, you don't have to place the severity for each component. |
1207 | daniel-mar | 60 | You can just leave it at the beginning. For example, `[WARN]OID(x)+RA(x)` is equal to `[WARN]OID(x)+[WARN]RA(x)`. |
1267 | daniel-mar | 61 | You can also put different severities for the components, e.g. `[INFO]OID(x)+[WARN]RA(x)` |
62 | would be an informative message (`INFO`) for the OID, but a warning (`WARN`) for the RA. |
||
1207 | daniel-mar | 63 | |
1267 | daniel-mar | 64 | ### Online/Offline dependency |
1207 | daniel-mar | 65 | |
1267 | daniel-mar | 66 | If you want to make the logging event dependent on whether |
67 | the target (`A`, `RA`, `OIDRA`, `SUPOIDRA`) matches the currently |
||
68 | logged-in user or not, write `[S1/S2]` where `S1` is the severity |
||
69 | when the logged-in user is the target |
||
70 | and `S2` is the severity when the user is not logged in or |
||
71 | logged in as a user not matching the target. |
||
1207 | daniel-mar | 72 | |
1267 | daniel-mar | 73 | With this technique, you can achieve that the RA gets warned if an admin or superior RA |
74 | changed some of their OIDs without their knowledge, |
||
75 | but receives a success message if they did the change themselves. |
||
1207 | daniel-mar | 76 | |
1267 | daniel-mar | 77 | Example: `[OK/WARN]RA(x)+[OK/INFO]A` means that there are two log messages generated: |
78 | - Message 1: If the currently logged-in user (performing the action) |
||
79 | is RA "x", then it is a success message (`OK`) for them, |
||
80 | otherwise it is a warning (`WARN`) for them, |
||
81 | i.e. they get warned that someone else (admin or superior RA) |
||
82 | has changed something without their knowledge. |
||
83 | - Message 2: If the currently logged-in user (performing the action) |
||
84 | is the administrator of the system, then it is a success message (`OK`) |
||
85 | for them, otherwise it is an informative message (`INFO`) for them, |
||
86 | i.e. the admin gets informed that a RA has done something. |
||
1207 | daniel-mar | 87 | |
1267 | daniel-mar | 88 | You can use the special severity `NONE` to achieve that an event is |
89 | not logged, so `NONE/...` means that the event is not logged |
||
90 | if the currently logged-in user matches the target, |
||
91 | and `.../NONE` means that the event is not logged if the user |
||
92 | is not logged in or logged in as a user not matching the target. |
||
1207 | daniel-mar | 93 | |
1267 | daniel-mar | 94 | Example: `[OK/NONE]RA(x)+[OK/NONE]A` could be used |
95 | to give the RA or the admin a success message (`OK`) |
||
96 | for their action, but the admin won't be notified if the |
||
97 | RA has changed it, and the RA won't be notified if the |
||
98 | admin changed it. An Exception is if the user is logged in |
||
99 | with both accounts (RA and admin) at the same time (which is |
||
100 | possible with OIDplus), then two log messages would be generated. |
||
1207 | daniel-mar | 101 | |
1267 | daniel-mar | 102 | The severities `[NONE]` and `[NONE/NONE]` are invalid, because they are meaningless. |
1207 | daniel-mar | 103 | |
1267 | daniel-mar | 104 | The online/offline dependency is only possible for the types `OIDRA`, `SUPOIDRA`, `RA`, and `A`, |
105 | but not for `OID` or `SUPOID`. |
||
1207 | daniel-mar | 106 | |
1267 | daniel-mar | 107 | ### Valid types |
1207 | daniel-mar | 108 | |
1267 | daniel-mar | 109 | Besides the severity, the component has a payload in the form `Type(Value)`. |
1207 | daniel-mar | 110 | |
1267 | daniel-mar | 111 | `OID(x)` means: Save the log entry into the logbook of object "x". |
1207 | daniel-mar | 112 | |
1267 | daniel-mar | 113 | `SUPOID(x)` means: Save the log entry into the logbook of the parent of object "x". |
1207 | daniel-mar | 114 | |
1267 | daniel-mar | 115 | `OIDRA(x)` means: Save the log entry into the logbook of the RA of object "x". |
116 | |||
117 | `SUPOIDRA(x)` means: Save the log entry into the logbook of the RA that owns the superior object of "x". |
||
118 | |||
119 | `RA(x)` means: Save the log entry into the logbook of the RA "x". |
||
120 | |||
121 | `A` means: Save the log entry into the logbook of the administrator of the system. |
||
122 | |||
123 | ### Escaping |
||
124 | |||
125 | Inside a severity block, you can escape []/\ with \ |
||
126 | |||
127 | Inside the value, you can escape ()+\ with \ |
||
128 | |||
129 | ## Implementation |
||
130 | |||
1209 | daniel-mar | 131 | You can find the implementation in **includes/classes/OIDplusLogger.class.php**. |
1267 | daniel-mar | 132 | |
133 | ## Tests |
||
134 | |||
135 | To check if your mask codes have the correct syntax, run the tool **dev/logger/verify_maskcodes.phps**. |