-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBioJava3_logging.html
More file actions
124 lines (121 loc) · 4.56 KB
/
BioJava3_logging.html
File metadata and controls
124 lines (121 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<h2 id="biojava-logging-usage-policy">BioJava Logging Usage Policy</h2>
<ul>
<li>SLF4J established as BioJava logging facade
<ul>
<li><a href="http://www.slf4j.org/">http://www.slf4j.org/</a></li>
</ul>
</li>
<li>Standard for initializing logger by class
<ul>
<li><code class="highlighter-rouge">private final static Logger logger = LoggerFactory.getLogger(<<Class_Name.class>>);</code></li>
<li>Where <<Class_Name.class>> like “BioJavaAADemo.class”
<ul>
<li>Note, use current (this) class’ name</li>
</ul>
</li>
</ul>
</li>
<li>Use SLF4J substitution pattern (<code class="highlighter-rouge">‘{}’</code>)
<ul>
<li>Most importantly, for efficiency. String concatenation is
avoided and toString() is not called if the logging statement is
filtered.
<ul>
<li>Meaning if logging level is set to INFO, then all strings in
any DEBUG statements will not be concatenated/toString()’d</li>
<li>Also, calls to <code class="highlighter-rouge">isDebugEnabled()</code> or DEBUG constant is not
necessary and redundant</li>
</ul>
</li>
<li>Enhances readability/conciseness</li>
<li>Example:
<code class="highlighter-rouge">logger.info("Protein Sequence: {}, Peptide Properties: {}", pSequence.getAccession(), peptide.getIsoelectricPoint(pSequence));</code></li>
</ul>
</li>
<li>No “magic” logs; meaning logs should stand alone, and be reasonable
understandable to an independent developer.
<ul>
<li>No printing of random IDs standalone
<ul>
<li><code class="highlighter-rouge">logger.info(protein.getAccesstion());</code></li>
</ul>
</li>
<li>No random symbols
<ul>
<li><code class="highlighter-rouge">logger.debug(“>>>@+”);</code></li>
</ul>
</li>
<li>Mostly, just add context to the log statement</li>
</ul>
</li>
<li>Demo classes
<ul>
<li>Should use <code class="highlighter-rouge">System.out</code> for logging and other output
<ul>
<li>For simplicity</li>
</ul>
</li>
</ul>
</li>
<li>Logging Levels
<ul>
<li>Production, log level set to: WARN</li>
<li>Test, log level set to: INFO</li>
<li>Error (logger.error)
<ul>
<li>Serious issue, fatal error, process can not continue.</li>
<li>Must be investigated immediately.</li>
<li>No system can tolerate items logged on this level.</li>
<li><u>Example</u>: NPE, database unavailable, mission critical
use case cannot be continued.</li>
</ul>
</li>
<li>Warning (logger.warn)
<ul>
<li>The process may be able to continue, but not necessarily
guaranteed.</li>
<li>The application may be able to tolerate warning messages,
but they should always be justified and examined.</li>
<li><u>Example</u>: “Application running in development mode”,
“Administration console is not secured with a password”, or
“Format not recognized”.</li>
</ul>
</li>
<li>Info (logger.info)
<ul>
<li>Important business process information
<ul>
<li>Process started/finished</li>
</ul>
</li>
<li>In an ideal world, administrator or advanced user should be
able to understand INFO messages and quickly find out what
the application is doing.</li>
<li>An action that changes the state of the application
significantly (database update, external system request).</li>
<li><u>Example</u>: 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]“.</li>
</ul>
</li>
<li>Debug (logger.debug)
<ul>
<li>Developers stuff exclusively.</li>
</ul>
</li>
<li>Trace (logger.trace)
<ul>
<li>Very detailed information, intended only for development.</li>
<li>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.</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="references">References</h3>
<p>Data in “Logging Levels” section borrowed from:
<a href="http://www.javacodegeeks.com/2011/01/10-tips-proper-application-logging.html">http://www.javacodegeeks.com/2011/01/10-tips-proper-application-logging.html</a></p>