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