---
title: BioJava3 logging
---
BioJava Logging Usage Policy
----------------------------
- SLF4J established as BioJava logging facade
-
- Standard for initializing logger by class
- `private final static Logger logger = LoggerFactory.getLogger(<>);`
- Where \<\> like âBioJavaAADemo.classâ
- Note, use current (this) classâ name
- Use SLF4J substitution pattern (`â{}â`)
- Most importantly, for efficiency. String concatenation is
avoided and toString() is not called if the logging statement is
filtered.
- Meaning if logging level is set to INFO, then all strings in
any DEBUG statements will not be concatenated/toString()âd
- Also, calls to `isDebugEnabled()` or DEBUG constant is not
necessary and redundant
- Enhances readability/conciseness
- Example:
`logger.info("Protein Sequence: {}, Peptide Properties: {}", pSequence.getAccession(), peptide.getIsoelectricPoint(pSequence));`
- No âmagicâ logs; meaning logs should stand alone, and be reasonable
understandable to an independent developer.
- No printing of random IDs standalone
- `logger.info(protein.getAccesstion());`
- No random symbols
- `logger.debug(â>>>@+â);`
- Mostly, just add context to the log statement
- Demo classes
- Should use `System.out` for logging and other output
- For simplicity
- Logging Levels
- Production, log level set to: WARN
- Test, log level set to: INFO
- Error (logger.error)
- Serious issue, fatal error, process can not continue.
- Must be investigated immediately.
- No system can tolerate items logged on this level.
- Example: NPE, database unavailable, mission critical
use case cannot be continued.
- Warning (logger.warn)
- The process may be able to continue, but not necessarily
guaranteed.
- The application may be able to tolerate warning messages,
but they should always be justified and examined.
- Example: âApplication running in development modeâ,
âAdministration console is not secured with a passwordâ, or
âFormat not recognizedâ.
- Info (logger.info)
- Important business process information
- Process started/finished
- In an ideal world, administrator or advanced user should be
able to understand INFO messages and quickly find out what
the application is doing.
- An action that changes the state of the application
significantly (database update, external system request).
- Example: if an application is all about booking
airplane tickets, there should be only one INFO statement
per each ticket saying â[Who] booked ticket from [Where] to
[Where]â.
- Debug (logger.debug)
- Developers stuff exclusively.
- Trace (logger.trace)
- Very detailed information, intended only for development.
- The distinction between DEBUG and TRACE is the most
difficult, but if you put logging statement and remove it
after the feature has been developed and tested, it should
probably be on TRACE level.
### References
Data in âLogging Levelsâ section borrowed from: