|
| 1 | +--- |
| 2 | +title: BioJava3 logging |
| 3 | +--- |
| 4 | + |
| 5 | +BioJava Logging Usage Policy |
| 6 | +---------------------------- |
| 7 | + |
| 8 | +- SLF4J established as BioJava logging facade |
| 9 | + - <http://www.slf4j.org/> |
| 10 | +- Standard for initializing logger by class |
| 11 | + - `private final static Logger logger = LoggerFactory.getLogger(<<Class_Name.class>>);` |
| 12 | + - Where \<<Class_Name.class>\> like “BioJavaAADemo.class” |
| 13 | + - Note, use current (this) class’ name |
| 14 | +- Use SLF4J substitution pattern (`‘{}’`) |
| 15 | + - Most importantly, for efficiency. String concatenation is |
| 16 | + avoided and toString() is not called if the logging statement is |
| 17 | + filtered. |
| 18 | + - Meaning if logging level is set to INFO, then all strings in |
| 19 | + any debug statements will not be concatenated/toString()’d |
| 20 | + - Also, calls to `isDebugEnabled()` or DEBUG constant is not |
| 21 | + necessary and redundant |
| 22 | + - Enhances readability/conciseness |
| 23 | + - Example: |
| 24 | + `logger.info("Protein Sequence: {}, Peptide Properties: {}", pSequence.getAccession(), peptide.getIsoelectricPoint(pSequence));` |
| 25 | +- No “magic” logs; meaning logs should stand alone, and be reasonable |
| 26 | + understandable to an independent developer. |
| 27 | + - No printing of random IDs standalone |
| 28 | + - `logger.info(protein.getAccesstion());` |
| 29 | + - No random symbols |
| 30 | + - `logger.debug(“>>>@+”);` |
| 31 | + - Mostly, just add context to the log statement |
| 32 | +- Demo classes |
| 33 | + - Should use `System.out` for logging and other output |
| 34 | + - For simplicity |
| 35 | +- Logging Levels |
| 36 | + - Production, log level set to: WARN |
| 37 | + - Test, log level set to: INFO |
| 38 | + - Error (logger.error) |
| 39 | + - Serious issue, fatal error, process can not continue. |
| 40 | + - Must be investigated immediately. |
| 41 | + - No system can tolerate items logged on this level. |
| 42 | + - <u>Example</u>: NPE, database unavailable, mission critical |
| 43 | + use case cannot be continued. |
| 44 | + - Warning (logger.warn) |
| 45 | + - The process may be able to continue, but not necessarily |
| 46 | + guaranteed. |
| 47 | + - The application may be able to tolerate warning messages, |
| 48 | + but they should always be justified and examined. |
| 49 | + - <u>Example</u>: “Application running in development mode”, |
| 50 | + “Administration console is not secured with a password”, or |
| 51 | + “Format not recognized”. |
| 52 | + - Info (logger.info) |
| 53 | + - Important business process information |
| 54 | + - Process started/finished |
| 55 | + - In an ideal world, administrator or advanced user should be |
| 56 | + able to understand INFO messages and quickly find out what |
| 57 | + the application is doing. |
| 58 | + - An action that changes the state of the application |
| 59 | + significantly (database update, external system request). |
| 60 | + - <u>Example</u>: if an application is all about booking |
| 61 | + airplane tickets, there should be only one INFO statement |
| 62 | + per each ticket saying “[Who] booked ticket from [Where] to |
| 63 | + [Where]“. |
| 64 | + - Debug (logger.debug) |
| 65 | + - Developers stuff exclusively. |
| 66 | + - Trace (logger.trace) |
| 67 | + - Very detailed information, intended only for development. |
| 68 | + - The distinction between DEBUG and TRACE is the most |
| 69 | + difficult, but if you put logging statement and remove it |
| 70 | + after the feature has been developed and tested, it should |
| 71 | + probably be on TRACE level. |
| 72 | + |
| 73 | +### References |
| 74 | + |
| 75 | +Data in “Logging Levels” section borrowed from: |
| 76 | +<http://www.javacodegeeks.com/2011/01/10-tips-proper-application-logging.html> |
0 commit comments