Reformat Logging text to add headings and TOC
[logging-analytics.git] / docs / index.rst
1
2
3
4
5 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
6 .. http://creativecommons.org/licenses/by/4.0
7 .. Copyright © 2017 AT&T Intellectual Property. All rights reserved.
8
9 Logging Enhancements Project
10 ==================================================
11 .. contents::
12    :depth: 3
13 ..
14
15 ONAP consists of many components and containers, and consequently writes
16 to many logfiles. The volume of logger output may be enormous,
17 especially when debugging. Large, disparate logfiles are difficult to
18 monitor and analyze, and tracing requests across many files, file
19 systems and containers is untenable without tooling. 
20
21 The problem of decentralized logger output is addressed by analytics
22 pipelines such as \ `*Elastic
23 Stack* <https://www.elastic.co/products>`__ (ELK). Elastic Stack
24 consumes logs, indexes their contents
25 in \ `*Elasticsearch* <https://www.elastic.co/products/elasticsearch>`__,
26 and makes them accessible, queryable and navigable via a sophisticated
27 UI, \ `*Kibana
28 Discover* <https://www.elastic.co/guide/en/kibana/current/discover.html>`__.
29 This elevates the importance of standardization and machine-readability.
30 Logfiles can remain browsable, but output can be simplified.
31
32 Logger configurations in ONAP are diverse and idiosyncratic. Addressing
33 these issues will prevent costs from being externalized to consumers
34 such as analytics. It also affords the opportunity to remedy any issues
35 with the handling and propagation of contextual information such as
36 transaction identifiers (presently passed as \ **X-ECOMP-RequestID **-
37 to be\ ** X-ONAP-RequestID**). This propagation is critical to tracing
38 requests as they traverse ONAP and related systems, and is the basis for
39 many analytics functions. 
40
41 Rationalized logger configuration and output also paves the way for
42 other high-performance logger transports, including publishing directly
43 to analytics via SYSLOG
44 (`*RFC3164* <https://www.ietf.org/rfc/rfc3164.txt>`__, \ `*RFC5425* <https://www.ietf.org/rfc/rfc5425.txt>`__, \ `*RFC5426* <https://www.ietf.org/rfc/rfc5426.txt>`__)
45 and streams, and mechanisms for durability.
46
47 Each change is believed to be individually beneficial:
48
49 1. The intention is to consolidate the required setup within this
50    project however some changes and bug fixes might have to be applied
51    in the relative component project, requiring each components'
52    co-operation on the contribution.
53
54 2. There is an economy of scale if everything can happen under a single
55    remit.
56
57 3. Standardization benefits all, including those who want to deviate
58    from defaults.
59
60 ONAP Application Logging Guidelines v1.1
61 ========================================
62
63 Introduction
64 ------------
65
66 The purpose of ONAP logging is to capture information needed to operate,
67 troubleshoot and report on the performance of the ONAP platform and its
68 constituent components. Log records may be viewed and consumed directly
69 by users and systems, indexed and loaded into a datastore, and used to
70 compute metrics and generate reports. 
71
72 The processing of a single client request will often involve multiple
73 ONAP components and/or subcomponents (interchangeably referred to as
74 application in this document). The ability to track flows across
75 components is critical to understanding ONAPs behavior and performance.
76 ONAP logging uses a universally unique RequestID value in log records to
77 track the processing of every client request through all the ONAP
78 components involved in its processing.
79
80 A reference configuration of \ `*Elastic
81 Stack * <https://www.elastic.co/products>`__\ can be deployed
82 using \ `*ONAP Operations
83 Manager* <https://wiki.onap.org/display/DW/ONAP+Operations+Manager+Project>`__. 
84
85 This document gives conventions you can follow to generate conformant,
86 indexable logging output from your component.
87
88 How to Log
89 ----------
90
91 ONAP prescribes conventions. The use of certain APIs and providers is
92 recommended, but they are not mandatory. Most components log
93 via \ `*EELF* <https://github.com/att/EELF>`__ or `*SLF4J* <https://www.slf4j.org/>`__ to
94 a provider
95 like \ `*Logback* <https://logback.qos.ch/>`__ or `*Log4j* <https://logging.apache.org/log4j/2.x/>`__.
96
97 ****
98 EELF
99 ****
100
101 EELF is the\ **Event and Error Logging Framework**, described
102 at \ `*https://github.com/att/EELF* <https://github.com/att/EELF>`__.
103
104 EELF abstracts your choice of logging provider, and decorates the
105 familiar Logger contracts with features like:
106
107 -  Localization.
108
109 -  Error codes. 
110
111 -  Generated wiki documentation.
112
113 -  Separate audit, metric, security and debug logs.
114
115 EELF is a facade, so logging output is configured in two ways:
116
117 1. By selection of a logging provider such as Logback or Log4j,
118    typically via the classpath. 
119
120 2. By way of a provider configuration document,
121    typically \ **logback.xml** or **log4j.xml**.
122    See \ `*Providers* <https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-Providers>`__.
123
124 *****
125 SLF4J
126 *****
127
128 `*SLF4J* <https://www.slf4j.org/>`__ is a logging facade, and a humble
129 masterpiece. It combines what's common to all major, modern Java logging
130 providers into a single interface. This decouples the caller from the
131 provider, and encourages the use of what's universal, familiar and
132 proven. 
133
134 EELF also logs via SLF4J's abstractions.
135
136 *********
137 Providers
138 *********
139
140 Logging providers are normally enabled by their presence in the
141 classpath. This means the decision may have been made for you, in some
142 cases implicitly by dependencies. If you have a strong preference then
143 you can change providers, but since the implementation is typically
144 abstracted behind EELF or SLF4J, it may not be worth the effort.
145
146 *******
147 Logback
148 *******
149
150 Logback is the most commonly used provider. It is generally configured
151 by an XML document named \ **logback.xml**.
152 See \ `*Configuration* <https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-Configuration>`__.
153
154 *************
155 Log4j 2.X
156 *************
157
158 Log4j 2.X is somewhat less common than Logback, but equivalent. It is
159 generally configured by an XML document
160 named \ **log4j.xml**. See \ `*Configuration* <https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-Configuration>`__.
161
162 *********
163 Log4j 1.X
164 *********
165
166 Avoid, since 1.X is EOL, and since it does not support escaping, so its
167 output may not be
168 machine-readable. See \ `*https://logging.apache.org/log4j/1.2/* <https://logging.apache.org/log4j/1.2/>`__.
169
170 This affects existing OpenDaylight-based components like SDNC and APPC,
171 since ODL releases prior
172 to \ `*Carbon* <https://www.opendaylight.org/what-we-do/current-release>`__ bundle
173 Log4j 1.X, and make it difficult to replace. The \ `*Common Controller
174 SDK
175 Project* <https://wiki.onap.org/display/DW/Common+Controller+SDK+Project>`__ project
176 targets ODL Carbon, so the problem should resolve in time.
177
178 What to Log
179 ===========
180
181 The purpose of logging is to capture diagnostic information.
182
183 An important aspect of this is analytics, which requires tracing of
184 requests between components. In a large, distributed system such as ONAP
185 this is critical to understanding behavior and performance. 
186
187 Messages, Levels, Components and Categories
188 --------------------------------------------
189
190 It isn't the aim of this document to reiterate the basics, so advice
191 here is general: 
192
193 -  Use a logger. Consider using EELF. 
194
195 -  Write log messages in English.
196
197 -  Write meaningful messages. Consider what will be useful to consumers
198    of logger output. 
199
200 -  Use errorcodes to characterise exceptions.
201
202 -  Log at the appropriate level. Be aware of the volume of logs that
203    will be produced.
204
205 -  Log in a machine-readable format. See Conventions.
206
207 -  Log for analytics as well as troubleshooting.
208
209 Others have written extensively on this: 
210
211 -  `*http://www.masterzen.fr/2013/01/13/the-10-commandments-of-logging/* <http://www.masterzen.fr/2013/01/13/the-10-commandments-of-logging/>`__
212
213 -  `*https://www.loggly.com/blog/how-to-write-effective-logs-for-remote-logging/* <https://www.loggly.com/blog/how-to-write-effective-logs-for-remote-logging/>`__
214
215 -  And so on.
216
217 Context
218 -------
219
220 **TODO: more on the importance of transaction ID propagation.**
221
222 MDCs
223 ====
224
225
226 A Mapped Diagnostic Context (MDC) allows an arbitrary string-valued
227 attribute to be attached to a Java thread. The MDC's value is then
228 emitted with each log message. The set of MDCs associated with a log
229 message is serialized as unordered name-value pairs (see `*Text
230 Output* <https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-TextOutput>`__).
231
232 A good discussion of MDCs can be found
233 at \ `*https://logback.qos.ch/manual/mdc.html* <https://logback.qos.ch/manual/mdc.html>`__. 
234
235 **MDCs:**
236
237 -  Must be set as early in invocation as possible. 
238
239 -  Must be unset on exit. 
240
241 Logging
242 -------
243
244 **Via SLF4J:**
245
246 +------+-------------------------------------------------------------------------------------+
247 | 1    | import java.util.UUID;                                                              |
248 |      |                                                                                     |
249 | 2    | import org.slf4j.Logger;                                                            |
250 |      |                                                                                     |
251 | 3    | import org.slf4j.LoggerFactory;                                                     |
252 |      |                                                                                     |
253 | 4    | import org.slf4j.MDC;                                                               |
254 |      |                                                                                     |
255 | 5    | // ...                                                                              |
256 |      |                                                                                     |
257 | 6    | final Logger logger = LoggerFactory.getLogger(this.getClass());                     |
258 |      |                                                                                     |
259 | 7    | MDC.put("SomeUUID", UUID.randomUUID().toString());                                  |
260 |      |                                                                                     |
261 | 8    | try {                                                                               |
262 |      |                                                                                     |
263 | 9    |     logger.info("This message will have a UUID-valued 'SomeUUID' MDC attached.");   |
264 |      |                                                                                     |
265 | 10   |     // ...                                                                          |
266 |      |                                                                                     |
267 | 11   | }                                                                                   |
268 |      |                                                                                     |
269 | 12   | finally {                                                                           |
270 |      |                                                                                     |
271 | 13   |     MDC.clear();                                                                    |
272 |      |                                                                                     |
273 | 14   | }                                                                                   |
274 +------+-------------------------------------------------------------------------------------+
275
276 EELF doesn't directly support MDCs, but SLF4J will receive any MDC that
277 is set (where **com.att.eelf.configuration.SLF4jWrapper** is the
278 configured EELF provider):
279
280 +------+-------------------------------------------------------------------------------------+
281 | 1    | import java.util.UUID;                                                              |
282 |      |                                                                                     |
283 | 2    | import org.slf4j.Logger;                                                            |
284 |      |                                                                                     |
285 | 3    | import org.slf4j.LoggerFactory;                                                     |
286 |      |                                                                                     |
287 | 4    | import org.slf4j.MDC;                                                               |
288 |      |                                                                                     |
289 | 5    | import com.att.eelf.configuration.EELFLogger;                                       |
290 |      |                                                                                     |
291 | 6    | import com.att.eelf.configuration.EELFManager;                                      |
292 |      |                                                                                     |
293 | 7    | // ...                                                                              |
294 |      |                                                                                     |
295 | 8    | final EELFLogger logger = EELFManager.getInstance().getLogger(this.getClass());     |
296 |      |                                                                                     |
297 | 9    | MDC.put("SomeUUID", UUID.randomUUID().toString());                                  |
298 |      |                                                                                     |
299 | 10   | try {                                                                               |
300 |      |                                                                                     |
301 | 11   |     logger.info("This message will have a UUID-valued 'SomeUUID' MDC attached.");   |
302 |      |                                                                                     |
303 | 12   |     // ...                                                                          |
304 |      |                                                                                     |
305 | 13   | }                                                                                   |
306 |      |                                                                                     |
307 | 14   | finally {                                                                           |
308 |      |                                                                                     |
309 | 15   |     MDC.clear();                                                                    |
310 |      |                                                                                     |
311 | 16   | }                                                                                   |
312 +------+-------------------------------------------------------------------------------------+
313
314 Serializing
315 -----------
316
317 Output of MDCs must ensure that:
318
319 -  All reported MDCs are logged with both name AND value. Logging output
320    should not treat any MDCs as special.
321
322 -  All MDC names and values are escaped.
323
324 Escaping in Logback configuration can be achieved with:
325
326 +-----+------------------------------------------------------------------+
327 | 1   | %replace(%replace(%mdc){'\\t','\\\\\\\\t'}){'\\n','\\\\\\\\n'}   |
328 +-----+------------------------------------------------------------------+
329
330 MDC - RequestID
331 ---------------
332
333 This is often referred to by other names, including "Transaction ID",
334 and one of several (pre-standardization) REST header names
335 including \ **X-ECOMP-RequestID** and **X-ONAP-RequestID**.
336
337 ONAP logging uses a universally unique "**RequestID"** value in log
338 records to track the processing of each client request across all the
339 ONAP components involved in its processing.
340
341 This value:
342
343 -  Is logged as a \ **RequestID** MDC. 
344
345 -  Is propagated between components in REST calls as
346    an \ **X-TransactionID** HTTP header.
347
348 Receiving the \ **X-TransactionID** will vary by component according to
349 APIs and frameworks. In general:
350
351 +-----+--------------------------------------------------------------------------+
352 | 1   | import javax.ws.rs.core.HttpHeaders;                                     |
353 |     |                                                                          |
354 | 2   | // ...                                                                   |
355 |     |                                                                          |
356 | 3   | final HttpHeaders headers = ...;                                         |
357 |     |                                                                          |
358 | 4   | // ...                                                                   |
359 |     |                                                                          |
360 | 5   | String txId = headers.getRequestHeaders().getFirst("X-TransactionID");   |
361 |     |                                                                          |
362 | 6   | if (StringUtils.isBlank(txId)) {                                         |
363 |     |                                                                          |
364 | 7   |     txId = UUID.randomUUID().toString();                                 |
365 |     |                                                                          |
366 | 8   | }                                                                        |
367 |     |                                                                          |
368 | 9   | MDC.put("RequestID", txID);                                              |
369 +-----+--------------------------------------------------------------------------+
370
371 Setting the \ **X-TransactionID** likewise will vary. For example:
372
373 +-----+---------------------------------------------------+
374 | 1   | final String txID = MDC.get("RequestID");         |
375 |     |                                                   |
376 | 2   | HttpURLConnection cx = ...;                       |
377 |     |                                                   |
378 | 3   | // ...                                            |
379 |     |                                                   |
380 | 4   | cx.setRequestProperty("X-TransactionID", txID);   |
381 +-----+---------------------------------------------------+
382
383 MDC - InvocationID
384 ------------------
385
386 **InvocationID** is similar to \ **RequestID**, but
387 where \ **RequestID** correlates records relating a single, top-level
388 invocation of ONAP as it traverses many
389 systems, \ **InvocationID** correlates log entries relating to a single
390 invocation of a single component. Typically this means via REST, but in
391 certain cases an \ **InvocationID** may be allocated without a new
392 invocation, e.g. when a request is retried.
393
394 **RequestID** and** InvocationID** allow an execution graph to be
395 derived. This requires that:
396
397 -  The relationship between \ **RequestID** and **InvocationID** is
398    reported. 
399
400 -  The relationship between caller and recipient is reported for each
401    invocation.
402
403 The proposed approach is that:
404
405 -  Callers:
406
407    -  Issue a new, unique \ **InvocationID** UUID for each downstream
408       call they make. 
409
410    -  Log the new \ **InvocationID**, indicating the intent to invoke:
411
412       -  With Markers \ **INVOKE**, and \ **SYNCHRONOUS** if the
413          invocation is synchronous.
414
415       -  With their own \ **InvocationID** still set as an MDC.
416
417    -  Pass the \ **InvocationID** as an \ **X-InvocationID** REST
418       header.
419
420 -  Invoked components:
421
422    -  Retrieve the \ **InvocationID** from REST headers upon invocation,
423       or generate a UUID default. 
424
425    -  Set the \ **InvocationID** MDC.
426
427    -  Write a log entry with the Marker \ **ENTRY**. (In EELF this will
428       be to the AUDIT log).
429
430    -  Act as per Callers in all downstream requests. 
431
432    -  Write a log entry with the Marker \ **EXIT** upon return. (In EELF
433       this will be to the METRIC log).
434
435    -  Unset all MDCs on exit.
436
437 That seems onerous, but:
438
439 -  It's only a few calls. 
440
441 -  It can be largely abstracted in the case of EELF logging.
442
443 **TODO: code.**
444
445 MDCs - the Rest
446 ---------------
447
448 Other MDCs are logged in a wide range of contexts.
449
450 Certain MDCs and their semantics may be specific to EELF log types.
451
452 **TODO: cross-reference EELF output to v1 doc.**
453
454 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
455 | **ID**   | **MDC**               | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | **Required**   | **EELF Audit**   | **EELF Metric**   | **EELF Error**   | **EELF Debug**   |
456 +==========+=======================+================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================+================+==================+===================+==================+==================+
457 | 1        | BeginTimestamp        | Date-time that processing activities being logged begins. The value should be represented in UTC and formatted per ISO 8601, such as œ2015-06-03T13:21:58+00:00\9d. The time should be shown with the maximum resolution available to the logging component (e.g., milliseconds, microseconds) by including the appropriate number of decimal digits. For example, when millisecond precision is available, the date-time value would be presented as, as œ2015-06-03T13:21:58.340+00:00\9d.                                                                                       | Y              |                  |                   |                  |                  |
458 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
459 | 2        | EndTimestamp          | Date-time that processing for the request or event being logged ends. Formatting rules are the same as for the BeginTimestamp field above.                                                                                                                                                                                                                                                                                                                                                                                                                                     | Y              |                  |                   |                  |                  |
460 |          |                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
461 |          |                       | In the case of a request that merely logs an event and has not subsequent processing, the EndTimestamp value may equal the BeginTimestamp value.                                                                                                                                                                                                                                                                                                                                                                                                                               |                |                  |                   |                  |                  |
462 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
463 | 3        | ElapsedTime           | This field contains the elapsed time to complete processing of an API call or transaction request (e.g., processing of a message that was received). This value should be the difference between. EndTimestamp and BeginTimestamp fields and must be expressed in milliseconds.                                                                                                                                                                                                                                                                                                | Y              |                  |                   |                  |                  |
464 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
465 | 4        | ServiceInstanceID     | This field is optional and should only be included if the information is readily available to the logging component.                                                                                                                                                                                                                                                                                                                                                                                                                                                           |                |                  |                   |                  |                  |
466 |          |                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
467 |          |                       | | Transaction requests that create or operate on a particular instance of a service/resource can                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                |                  |                   |                  |                  |
468 |          |                       | | identify/reference it via a unique œserviceInstanceID\9d value. This value can be used as a primary key for                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                |                  |                   |                  |                  |
469 |          |                       | | obtaining or updating additional detailed data about that specific service instance from the inventory                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                |                  |                   |                  |                  |
470 |          |                       | | (e.g., AAI). In other words:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |                |                  |                   |                  |                  |
471 |          |                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
472 |          |                       | -  In the case of processing/logging a transaction request for creating a new service instance, the serviceInstanceID value is determined by either a) the MSO client and passed to MSO or b) by MSO itself upon receipt of a such a request.                                                                                                                                                                                                                                                                                                                                  |                |                  |                   |                  |                  |
473 |          |                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
474 |          |                       | -  In other cases, the serviceInstanceID value can be used to reference a specific instance of a service as would happen in a œMACD\9d-type request.                                                                                                                                                                                                                                                                                                                                                                                                                             |                |                  |                   |                  |                  |
475 |          |                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
476 |          |                       | -  ServiceInstanceID is associated with a requestID in log records to facilitate tracing its processing over multiple requests and for a specific service instance. Its value may be left œempty\9d in subsequent record to the 1 st record where a requestID value is associated with the serviceInstanceID value.                                                                                                                                                                                                                                                              |                |                  |                   |                  |                  |
477 |          |                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
478 |          |                       | NOTE: AAI wont have a serviceInstanceUUID for every service instance. For example, no serviceInstanceUUID is available when the request is coming from an application that may import inventory data.                                                                                                                                                                                                                                                                                                                                                                          |                |                  |                   |                  |                  |
479 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
480 | 5        | VirtualServerName     | Physical/virtual server name. Optional: empty if determined that its value can be added by the agent that collects the log files collecting.                                                                                                                                                                                                                                                                                                                                                                                                                                   |                |                  |                   |                  |                  |
481 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
482 | 6        | ServiceName           | For Audit log records that capture API requests, this field contains the name of the API invoked at the component creating the record (e.g., Layer3ServiceActivateRequest).                                                                                                                                                                                                                                                                                                                                                                                                    | Y              |                  |                   |                  |                  |
483 |          |                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
484 |          |                       | For Audit log records that capture processing as a result of receipt of a message, this field should contain the name of the module that processes the message.                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
485 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
486 | 7        | PartnerName           | This field contains the name of the client application user agent or user invoking the API if known.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Y              |                  |                   |                  |                  |
487 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
488 | 8        | StatusCode            | This field indicates the high level status of the request. It must have the value COMPLETE when the request is successful and ERROR when there is a failure.                                                                                                                                                                                                                                                                                                                                                                                                                   | Y              |                  |                   |                  |                  |
489 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
490 | 9        | ResponseCode          | This field contains application-specific error codes. For consistency, common error categorizations should be used.                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                |                  |                   |                  |                  |
491 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
492 | 10       | ResponseDescription   | This field contains a human readable description of the \ **ResponseCode**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                |                  |                   |                  | 11               |
493 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
494 | 11       | InstanceUUID          | If known, this field contains a universally unique identifier used to differentiate between multiple instances of the same (named) log writing service/application. Its value is set at instance creation time (and read by it, e.g., at start/initialization time from the environment). This value should be picked up by the component instance from its configuration file and subsequently used to enable differentiation of log records created by multiple, locally load balanced ONAP component or subcomponent instances that are otherwise identically configured.   |                |                  |                   |                  |                  |
495 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
496 | 12       | Severity              | Optional: 0, 1, 2, 3 see \ `*Nagios* <https://en.wikipedia.org/wiki/Nagios>`__ monitoring/alerting for specifics/details.                                                                                                                                                                                                                                                                                                                                                                                                                                                      |                |                  |                   |                  |                  |
497 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
498 | 13       | TargetEntity          | It contains the name of the ONAP component or sub-component, or external entity, at which the operation activities captured in this metrics log record is invoked.                                                                                                                                                                                                                                                                                                                                                                                                             | Y              |                  |                   |                  |                  |
499 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
500 | 14       | TargetServiceName     | It contains the name of the API or operation activities invoked at the TargetEntity.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Y              |                  |                   |                  |                  |
501 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
502 | 15       | Server                | This field contains the Virtual Machine (VM) Fully Qualified Domain Name (FQDN) if the server is virtualized. Otherwise, it contains the host name of the logging component.                                                                                                                                                                                                                                                                                                                                                                                                   | Y              |                  |                   |                  |                  |
503 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
504 | 16       | ServerIPAddress       | This field contains the logging component host servers IP address if known (e.g. Jetty containers listening IP address). Otherwise it is empty.                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
505 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
506 | 17       | ServerFQDN            | Unclear, but possibly duplicating one or both of \ **Server** and **ServerIPAddress**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |                |                  |                   |                  |                  |
507 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
508 | 18       | ClientIPAddress       | This field contains the requesting remote client applications IP address if known. Otherwise this field can be empty.                                                                                                                                                                                                                                                                                                                                                                                                                                                          |                |                  |                   |                  |                  |
509 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
510 | 19       | ProcessKey            | This field can be used to capture the flow of a transaction through the system by indicating the components and operations involved in processing. If present, it can be denoted by a comma separated list of components and applications.                                                                                                                                                                                                                                                                                                                                     |                |                  |                   |                  |                  |
511 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
512 | 20       | RemoteHost            | Unknown.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                |                  |                   |                  |                  |
513 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
514 | 21       | AlertSeverity         | Unknown.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                |                  |                   |                  |                  |
515 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
516 | 22       | TargetVirtualEntity   | Unknown                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                |                  |                   |                  |                  |
517 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
518 | 23       | ClassName             | Defunct. Doesn't require an MDC.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                |                  |                   |                  |                  |
519 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
520 | 24       | ThreadID              | Defunct. Doesn't require an MDC.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                |                  |                   |                  |                  |
521 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
522 | 25       | CustomField1          | (Defunct now that MDCs are serialized as NVPs.)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
523 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
524 | 26       | CustomField2          | (Defunct now that MDCs are serialized as NVPs.)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
525 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
526 | 27       | CustomField3          | (Defunct now that MDCs are serialized as NVPs.)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
527 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
528 | 28       | CustomField4          | (Defunct now that MDCs are serialized as NVPs.)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                |                  |                   |                  |                  |
529 +----------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+------------------+-------------------+------------------+------------------+
530
531 Examples
532 --------
533
534 ******
535 SDC-BE
536 ******
537
538 20170907: audit.log
539
540 +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
541 | root@ip-172-31-93-160:/dockerdata-nfs/onap/sdc/logs/SDC/SDC-BE# tail -f audit.log                                                                                                                                             |
542 |                                                                                                                                                                                                                               |
543 | 2017-09-07T18:04:03.679Z\|\|\|\|\|qtp1013423070-72297\|\|ASDC\|SDC-BE\|\|\|\|\|\|\|N/A\|INFO\|\|\|\|10.42.88.30\|\|o.o.s.v.r.s.VendorLicenseModelsImpl\|\|ActivityType=<audit>, Desc=< --Audit-- Create VLM. VLM Name: lm4>   |
544 +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
545
546 **TODO: this is the earlier output format. Let's find an example which matches the latest line format.**
547
548 Markers
549 =======
550
551 Markers differ from MDCs in two important ways:
552
553 1. They have a name, but no value. They are a tag. 
554
555 2. Their scope is limited to logger calls which specifically reference
556    them; they are
557    not \ `*ThreadLocal* <https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html>`__. 
558
559 Logging
560 -------
561
562 **********
563 Via SLF4J:
564 **********
565
566 +-----+-----------------------------------------------------------------------+
567 | 1   | import org.slf4j.Logger;                                              |
568 |     |                                                                       |
569 | 2   | import org.slf4j.LoggerFactory;                                       |
570 |     |                                                                       |
571 | 3   | import org.slf4j.Marker;                                              |
572 |     |                                                                       |
573 | 4   | import org.slf4j.MarkerFactory;                                       |
574 |     |                                                                       |
575 | 5   | // ...                                                                |
576 |     |                                                                       |
577 | 6   | final Logger logger = LoggerFactory.getLogger(this.getClass());       |
578 |     |                                                                       |
579 | 7   | final Marker marker = MarkerFactory.getMarker("MY\_MARKER");          |
580 |     |                                                                       |
581 | 8   | logger.warn(marker, "This warning has a 'MY\_MARKER' annotation.");   |
582 +-----+-----------------------------------------------------------------------+
583
584 EELF does not allow Markers to be set directly. See notes on
585 the \ **InvocationID** MDC.
586
587 Serializing
588 -----------
589
590 Marker names also need to be escaped, though they're much less likely to
591 contain problematic characters than MDC values.
592
593 Escaping in Logback configuration can be achieved with:
594
595 +-----+---------------------------------------------------------------------+
596 | 1   | %replace(%replace(%marker){'\\t','\\\\\\\\t'}){'\\n','\\\\\\\\n'}   |
597 +-----+---------------------------------------------------------------------+
598
599 Marker - ENTRY
600 --------------
601
602 This should be reported as early in invocation as possible, immediately
603 after setting the \ **RequestID** and **InvocationID** MDCs.
604
605 It can be automatically set by EELF, and written to the AUDIT log. 
606
607 It must be manually set otherwise. 
608
609 *****
610 EELF
611 *****
612
613 **EELF**
614
615 +-----+----------+
616 | 1   | //TODO   |
617 +-----+----------+
618
619 *****
620 SLF4J
621 *****
622
623 **SLF4J**
624
625 +-----+------------------------------------------------------------------------+
626 | 1   | public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");   |
627 |     |                                                                        |
628 | 2   | // ...                                                                 |
629 |     |                                                                        |
630 | 3   | final Logger logger = LoggerFactory.getLogger(this.getClass());        |
631 |     |                                                                        |
632 | 4   | logger.debug(ENTRY, "Entering.");                                      |
633 +-----+------------------------------------------------------------------------+
634
635 Marker - EXIT
636 -------------
637
638 This should be reported as late in invocation as possible, immediately
639 before unsetting the \ **RequestID** and **InvocationID** MDCs.
640
641 It can be automatically reported by EELF, and written to the METRIC
642 log. 
643
644 It must be manually set otherwise.
645
646 *****
647 EELF
648 *****
649
650 **EELF**
651
652 +-----+----------+
653 | 1   | //TODO   |
654 +-----+----------+
655
656 ******
657 SLF4J
658 ******
659
660 **SLF4J**
661
662 +-----+----------------------------------------------------------------------+
663 | 1   | public static final Marker EXIT = MarkerFactory.getMarker("EXIT");   |
664 |     |                                                                      |
665 | 2   | // ...                                                               |
666 |     |                                                                      |
667 | 3   | final Logger logger = LoggerFactory.getLogger(this.getClass());      |
668 |     |                                                                      |
669 | 4   | logger.debug(EXIT, "Exiting.");                                      |
670 +-----+----------------------------------------------------------------------+
671
672 Marker - INVOKE
673 ---------------
674
675 This should be reported by the caller of another ONAP component via
676 REST, including a newly allocated \ **InvocationID**, which will be
677 passed to the caller. 
678
679 ******
680 SLF4J
681 ******
682
683 **SLF4J**
684
685 +------+--------------------------------------------------------------------------+
686 | 1    | public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");   |
687 |      |                                                                          |
688 | 2    | // ...                                                                   |
689 |      |                                                                          |
690 | 3    |                                                                          |
691 |      |                                                                          |
692 | 4    | // Generate and report invocation ID.                                    |
693 |      |                                                                          |
694 | 5    |                                                                          |
695 |      |                                                                          |
696 | 6    | final String invocationID = UUID.randomUUID().toString();                |
697 |      |                                                                          |
698 | 7    | MDC.put(MDC\_INVOCATION\_ID, invocationID);                              |
699 |      |                                                                          |
700 | 8    | try {                                                                    |
701 |      |                                                                          |
702 | 9    |     logger.debug(INVOKE\_SYNCHRONOUS, "Invoking synchronously ... ");    |
703 |      |                                                                          |
704 | 10   | }                                                                        |
705 |      |                                                                          |
706 | 11   | finally {                                                                |
707 |      |                                                                          |
708 | 12   |     MDC.remove(MDC\_INVOCATION\_ID);                                     |
709 |      |                                                                          |
710 | 13   | }                                                                        |
711 |      |                                                                          |
712 | 14   |                                                                          |
713 |      |                                                                          |
714 | 15   | // Pass invocationID as HTTP X-InvocationID header.                      |
715 |      |                                                                          |
716 | 16   |                                                                          |
717 |      |                                                                          |
718 | 17   | callDownstreamSystem(invocationID, ... );                                |
719 +------+--------------------------------------------------------------------------+
720
721 **TODO: EELF, without changing published APIs.**
722
723 Marker - SYNCHRONOUS
724 ------------------------
725
726 This should accompany \ **INVOKE** when the invocation is synchronous.
727
728 ******
729 SLF4J
730 ******
731
732 **SLF4J**
733
734 +------+-------------------------------------------------------------------------+
735 | 1    | public static final Marker INVOKE\_SYNCHRONOUS;                         |
736 |      |                                                                         |
737 | 2    | static {                                                                |
738 |      |                                                                         |
739 | 3    |     INVOKE\_SYNCHRONOUS = MarkerFactory.getMarker("INVOKE");            |
740 |      |                                                                         |
741 | 4    |     INVOKE\_SYNCHRONOUS.add(MarkerFactory.getMarker("SYNCHRONOUS"));    |
742 |      |                                                                         |
743 | 5    | }                                                                       |
744 |      |                                                                         |
745 | 6    | // ...                                                                  |
746 |      |                                                                         |
747 | 7    |                                                                         |
748 |      |                                                                         |
749 | 8    | // Generate and report invocation ID.                                   |
750 |      |                                                                         |
751 | 9    |                                                                         |
752 |      |                                                                         |
753 | 10   | final String invocationID = UUID.randomUUID().toString();               |
754 |      |                                                                         |
755 | 11   | MDC.put(MDC\_INVOCATION\_ID, invocationID);                             |
756 |      |                                                                         |
757 | 12   | try {                                                                   |
758 |      |                                                                         |
759 | 13   |     logger.debug(INVOKE\_SYNCHRONOUS, "Invoking synchronously ... ");   |
760 |      |                                                                         |
761 | 14   | }                                                                       |
762 |      |                                                                         |
763 | 15   | finally {                                                               |
764 |      |                                                                         |
765 | 16   |     MDC.remove(MDC\_INVOCATION\_ID);                                    |
766 |      |                                                                         |
767 | 17   | }                                                                       |
768 |      |                                                                         |
769 | 18   |                                                                         |
770 |      |                                                                         |
771 | 19   | // Pass invocationID as HTTP X-InvocationID header.                     |
772 |      |                                                                         |
773 | 20   |                                                                         |
774 |      |                                                                         |
775 | 21   | callDownstreamSystem(invocationID, ... );                               |
776 +------+-------------------------------------------------------------------------+
777
778 **TODO: EELF, without changing published APIs.**
779
780 Errorcodes
781 ==========
782
783 Errorcodes are reported as MDCs. 
784
785 Exceptions should be accompanied by an errrorcode. Typically this is
786 achieved by incorporating errorcodes into your exception hierarchy and
787 error handling. ONAP components generally do not share this kind of
788 code, though EELF defines a marker interface (meaning it has no
789 methods) \ **EELFResolvableErrorEnum**.
790
791 A common convention is for errorcodes to have two components:
792
793 1. A \ **prefix**, which identifies the origin of the error. 
794
795 2. A \ **suffix**, which identifies the kind of error.
796
797 Suffixes may be numeric or text. They may also be common to more than
798 one component.
799
800 For example:
801
802 +-----+-------------------------------+
803 | 1   | COMPONENT\_X.STORAGE\_ERROR   |
804 +-----+-------------------------------+
805
806 Output Format
807 -------------
808
809 Several considerations:
810
811 1. Logs should be human-readable (within reason). 
812
813 2. Shipper and indexing performance and durability depends on logs that
814    can be parsed quickly and reliably.
815
816 3. Consistency means fewer shipping and indexing rules are required.
817
818 ***********
819 Text Output
820 ***********
821
822 ONAP needs to strike a balance between human-readable and
823 machine-readable logs. This means:
824
825 -  The use of tab (**\\t**) as a delimiter.
826
827 -  Escaping all messages, exceptions, MDC values, Markers, etc. to
828    replace tabs in their content.
829
830 -  Escaping all newlines with \ **\\n** so that each entry is on one
831    line. 
832
833 In logback, this looks like:
834
835 +-----+-------------------------------------------------------------------------------+
836 | 1   | <property name="defaultPattern" value="%nopexception%logger                   |
837 |     |                                                                               |
838 | 2   | \\t%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC}                                    |
839 |     |                                                                               |
840 | 3   | \\t%level                                                                     |
841 |     |                                                                               |
842 | 4   | \\t%replace(%replace(%message){'\\t','\\\\\\\\t'}){'\\n','\\\\\\\\n'}         |
843 |     |                                                                               |
844 | 5   | \\t%replace(%replace(%mdc){'\\t','\\\\\\\\t'}){'\\n','\\\\\\\\n'}             |
845 |     |                                                                               |
846 | 6   | \\t%replace(%replace(%rootException){'\\t','\\\\\\\\t'}){'\\n','\\\\\\\\n'}   |
847 |     |                                                                               |
848 | 7   | \\t%replace(%replace(%marker){'\\t','\\\\\\\\t'}){'\\n','\\\\\\\\n'}          |
849 |     |                                                                               |
850 | 8   | \\t%thread                                                                    |
851 |     |                                                                               |
852 | 9   | \\t%n"/>                                                                      |
853 +-----+-------------------------------------------------------------------------------+
854
855 The output of which, with MDCs, a Marker and a nested exception, with newlines added for readability looks like:
856
857 TODO: remove tab below
858
859 +------+-----------------------------------------------------------------------------------------------------------------------------+
860 | 1    | org.onap.example.component1.subcomponent1.LogbackTest                                                                       |
861 |      |                                                                                                                             |
862 | 2    | \\t2017-08-06T16:09:03.594Z                                                                                                 |
863 |      |                                                                                                                             |
864 | 3    | \\tERROR                                                                                                                    |
865 |      |                                                                                                                             |
866 | 4    | \\tHere's an error, that's usually bad                                                                                      |
867 |      |                                                                                                                             |
868 | 5    | \\tkey1=value1, key2=value2 with space, key5=value5"with"quotes, key3=value3\\nwith\\nnewlines, key4=value4\\twith\\ttabs   |
869 |      |                                                                                                                             |
870 | 6    | \\tjava.lang.RuntimeException: Here's Johnny                                                                                |
871 |      |                                                                                                                             |
872 | 7    | \\n\\tat org.onap.example.component1.subcomponent1.LogbackTest.main(LogbackTest.java:24)                                    |
873 |      |                                                                                                                             |
874 | 8    | \\nWrapped by: java.lang.RuntimeException: Little pigs, little pigs, let me come in                                         |
875 |      |                                                                                                                             |
876 | 9    | \\n\\tat org.onap.example.component1.subcomponent1.LogbackTest.main(LogbackTest.java:27)                                    |
877 |      |                                                                                                                             |
878 | 10   | \\tAMarker1                                                                                                                 |
879 |      |                                                                                                                             |
880 | 11   | \\tmain                                                                                                                     |
881 +------+-----------------------------------------------------------------------------------------------------------------------------+
882
883 Default Logstash indexing rules understand output in this format.
884
885 **********
886 XML Output
887 **********
888
889 For Log4j 1.X output, since escaping is not supported, the best
890 alternative is to emit logs in XML format. 
891
892 There may be other instances where XML (or JSON) output may be
893 desirable. Default indexing rules support 
894
895 Default Logstash indexing rules understand the XML output of \ `*Log4J's
896 XMLLayout* <https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/XMLLayout.html>`__.
897
898 Output Location
899 ===============
900
901 Standardization of output locations makes logs easier to locate and ship
902 for indexing. 
903
904 Logfiles should default to beneath \ **/var/log**, and
905 beneath \ **/var/log/ONAP** in the case of core ONAP components:
906
907 +-----+-----------------------------------------------------+
908 | 1   | /var/log/ONAP/<component>[/<subcomponent>]/\*.log   |
909 +-----+-----------------------------------------------------+
910
911 Configuration
912 =============
913
914 Logging providers should be configured by file. Files should be at a
915 predictable, static location, so that they can be written by deployment
916 automation. Ideally this should be under \ **/etc/ONAP**, but compliance
917 is low.
918
919 Locations
920 =========
921
922 All logger provider configuration document locations namespaced by
923 component and (if applicable) subcomponent by default:
924
925 +-----+---------------------------------------------------------+
926 | 1   | /etc/onap/<component>[/<subcomponent>]/<provider>.xml   |
927 +-----+---------------------------------------------------------+
928
929 Where \ **<provider>.xml**, will typically be one of:
930
931 1. logback.xml
932
933 2. log4j.xml
934
935 3. log4j.properties
936
937 Reconfiguration
938 ===============
939
940 Logger providers should reconfigure themselves automatically when their
941 configuration file is rewritten. All major providers should support
942 this. 
943
944 The default interval is 10s. 
945
946 Overrides
947 =========
948
949 The location of the configuration file MAY be overrideable, for example
950 by an environment variable, but this is left for individual components
951 to decide. 
952
953 Archetypes
954 ============
955
956 Configuration archetypes can be found in the ONAP codebase. Choose
957 according to your provider, and whether you're logging via EELF. Efforts
958 to standardize them are underway, so the ones you should be looking for
959 are where pipe (\|) is used as a separator. (Previously it was "\|").
960
961 Retention
962 =========
963
964 Logfiles are often large. Logging providers allow retention policies to
965 be configured. 
966
967 Retention has to balance:
968
969 -  The need to index logs before they're removed. 
970
971 -  The need to retain logs for other (including regulatory) purposes. 
972
973 Defaults are subject to change. Currently they are:
974
975 1. Files <= 50MB before rollover. 
976
977 2. Files retain for 30 days. 
978
979 3. Total files capped at 10GB. 
980
981 In Logback configuration XML:
982
983 +------+-------------------------------------------------------------------------------------------------------------+
984 | 1    | <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">                              |
985 |      |                                                                                                             |
986 | 2    |     <file>${outputDirectory}/${outputFilename}.log</file>                                                   |
987 |      |                                                                                                             |
988 | 3    |     <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">                       |
989 |      |                                                                                                             |
990 | 4    |         <fileNamePattern>${outputDirectory}/${outputFilename}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>   |
991 |      |                                                                                                             |
992 | 5    |         <maxFileSize>50MB</maxFileSize>                                                                     |
993 |      |                                                                                                             |
994 | 6    |         <maxHistory>30</maxHistory>                                                                         |
995 |      |                                                                                                             |
996 | 7    |         <totalSizeCap>10GB</totalSizeCap>                                                                   |
997 |      |                                                                                                             |
998 | 8    |     </rollingPolicy>                                                                                        |
999 |      |                                                                                                             |
1000 | 9    |     <encoder>                                                                                               |
1001 |      |                                                                                                             |
1002 | 10   |         <!-- ... -->                                                                                        |
1003 |      |                                                                                                             |
1004 | 11   |     </encoder>                                                                                              |
1005 |      |                                                                                                             |
1006 | 12   | </appender>                                                                                                 |
1007 +------+-------------------------------------------------------------------------------------------------------------+
1008
1009 Types of EELF Logs
1010 ==================
1011
1012 EELF guidelines stipulate that an application should output log records
1013 to four separate files:
1014
1015 1. audit
1016
1017 2. metric
1018
1019 3. error
1020
1021 4. debug
1022
1023 This applies only to EELF logging. Components which log directly to a
1024 provider may choose to emit the same set of logs, but most do not. 
1025
1026 Audit Log
1027 ---------
1028
1029 An audit log is required for EELF-enabled components, and provides a
1030 summary view of the processing of a (e.g., transaction) request within
1031 an application. It captures activity requests that are received by an
1032 ONAP component, and includes such information as the time the activity
1033 is initiated, then it finishes, and the API that is invoked at the
1034 component.
1035
1036 Audit log records are intended to capture the high level view of
1037 activity within an ONAP component. Specifically, an API request handled
1038 by an ONAP component is reflected in a single Audit log record that
1039 captures the time the request was received, the time that processing was
1040 completed, as well as other information about the API request (e.g., API
1041 name, on whose behalf it was invoked, etc).
1042
1043 Metric Log
1044 ----------
1045
1046 A metric log is required for EELF-enabled components, and provides a
1047 more detailed view into the processing of a transaction within an
1048 application. It captures the beginning and ending of activities needed
1049 to complete it. These can include calls to or interactions with other
1050 ONAP or non-ONAP entities.
1051
1052 Suboperations invoked as part of the processing of the API request are
1053 logged in the Metrics log. For example, when a call is made to another
1054 ONAP component or external (i.e., non-ONAP) entity, a Metrics log record
1055 captures that call. In such a case, the Metrics log record indicates
1056 (among other things) the time the call is made, when it returns, the
1057 entity that is called, and the API invoked on that entity. The Metrics
1058 log record contain the same RequestID as the Audit log record so the two
1059 can be correlated.
1060
1061 Note that a single request may result in multiple Audit log records at
1062 an ONAP component and may result in multiple Metrics log records
1063 generated by the component when multiple suboperations are required to
1064 satisfy the API request captured in the Audit log record.
1065
1066 Error Log
1067 ---------
1068
1069 An error log is required for EELF-enabled components, and is intended to
1070 capture info, warn, error and fatal conditions sensed (œexception
1071 handled\9d) by the software components.
1072
1073 Debug Log
1074 ---------
1075
1076 A debug log is optional for EELF-enabled components, and is intended to
1077 capture whatever data may be needed to debug and correct abnormal
1078 conditions of the application.
1079
1080 Engine.out
1081 ==========
1082
1083 Console logging may also be present, and is intended to capture
1084 system/infrastructure records. That is stdout and stderr assigned to a
1085 single œengine.out file in a directory configurable (e.g. as an
1086 environment/shell variable) by operations personnel.
1087
1088 New ONAP Component Checklist
1089 ============================
1090
1091 By following a few simple rules:
1092
1093 -  Your component's output will be indexed automatically. 
1094
1095 -  Analytics will be able to trace invocation through your component.
1096
1097 Obligations fall into two categories:
1098
1099 1. Conventions regarding configuration, line format and output. 
1100
1101 2. Ensuring the propagation of contextual information. 
1102
1103 You must:
1104
1105 1. Choose a Logging provider and/or EELF. Decisions, decisions.
1106
1107 2. Create a configuration file based on an existing
1108    archetype. See \ `*Configuration* <https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-Configuration>`__.
1109
1110 3. Read your configuration file when your components initialize logging.
1111
1112 4. Write logs to a standard location so that they can be shipped by
1113    Filebeat for indexing. See \ `*Output
1114    Location* <https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-OutputLocation>`__.
1115
1116 5. Report transaction state:
1117
1118    a. Retrieve, default and propagate \ **RequestID**. See \ `*MDC -
1119       RequestID* <https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-MDC-RequestID>`__.
1120
1121    b. At each invocation of one ONAP component by another:
1122
1123       i.   Initialize and propagate \ **InvocationID**. See \ `*MDC -
1124            Invocation
1125            ID* <https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-MDC-InvocationID>`__.
1126
1127       ii.  Report \ **INVOKE** and **SYNCHRONOUS** markers in caller. 
1128
1129       iii. Report \ **ENTRY** and **EXIT** markers in recipient. 
1130
1131 6. Write useful logs!
1132
1133  They are unordered.