@<1133362765067456512|User B> • When logging exceptions, it’s considered a best practice to log the exceptions along with the associated meta data - Account Nr, PolicyNr, Quote Number, etc. The meta data will prove invaluable when troubleshooting issues in production . • To go one step further, the meta data should be logged in the Name Value format. • Here is an example of logging an exception in Name Value pair format.
The underlined files represent Meta data that can be easily searched by a splunk query. In the statement given below, UID, CRID, PAN, PCN represent UserID, JobID, Account#, and Policy# respectively. Now it becomes ridiculously easy to scan the logs and identify ERRORs associated to a particular Job#, Policy # etc.
An example of a splunk query that can quickly help zero in on the above entry is shown below. This SPLUNK query helps to narrow down the ERRORS associated to the Policy # = 1523669410.
The strategy to implement this logging is pretty simple.
- Create a class named LogEntry that contains all the placeholders for data is required while logging. See a sample implementation.
- Then create a centralized logger Class (LoggerUtil) that has the methods (such as logInfo, logError, logTrace, logDebug etc) that take in LogEntry as a parameter