summaryrefslogtreecommitdiff
path: root/docs/jacoco-ut/bjc.everge/LogStream.java.html
blob: 217734ade9416c68c9b073bc5ca82542432123e0 (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>LogStream.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">everge</a> &gt; <a href="index.source.html" class="el_package">bjc.everge</a> &gt; <span class="el_source">LogStream.java</span></div><h1>LogStream.java</h1><pre class="source lang-java linenums">package bjc.everge;

import java.io.*;

/**
 * Simple class used for logging with various levels.
 *
 * @author Ben Culkin
 */
public class LogStream {
	/**
	 * Log level for printing nothing.
	 */
	public static final int NOTHING = -1;

	/**
	 * Log level for printing only fatal errors.
	 */
	public static final int FATAL = 0;

	/**
	 * Log level for printing all errors.
	 */
	public static final int ERROR = 1;

	/**
	 * Log level for printing warnings.
	 */
	public static final int WARN = 2;

	/**
	 * Log level for printing info messages.
	 */
	public static final int INFO = 3;

	/**
	 * Log level for printing debug messages.
	 */
	public static final int DEBUG = 4;

	/**
	 * Log level for printing trace messages.
	 */
	public static final int TRACE = 5;

	private int verbosity;

	private PrintStream output;

	/**
	 * Create a new log stream.
	 *
	 * Defaults to printing only fatal errors.
	 *
	 * @param out
	 *            The output stream to place things into.
	 */
<span class="fc" id="L58">	public LogStream(PrintStream out) {</span>
<span class="fc" id="L59">		output = out;</span>
<span class="fc" id="L60">		verbosity = FATAL;</span>
<span class="fc" id="L61">	}</span>

	/**
	 * Create a new log stream.
	 *
	 * @param out
	 *              The output stream to place things into.
	 * @param level
	 *              The verbosity level. Use the constants in this class for the
	 *              values.
	 */
<span class="nc" id="L72">	public LogStream(PrintStream out, int level) {</span>
<span class="nc" id="L73">		output = out;</span>
<span class="nc" id="L74">		verbosity = level;</span>
<span class="nc" id="L75">	}</span>

	/**
	 * Get the verbosity of the stream.
	 * 
	 * @return The verbosity of the stream.
	 */
	public int verbosity() {
<span class="nc" id="L83">		return verbosity;</span>
	}

	/**
	 * Set the verbosity of the stream.
	 * 
	 * @param verb
	 *             The verbosity of the stream.
	 */
	public void verbosity(int verb) {
<span class="fc" id="L93">		verbosity = verb;</span>
<span class="fc" id="L94">	}</span>

	/**
	 * Increment the verbosity of the stream.
	 */
	public void louder() {
<span class="fc" id="L100">		louder(1);</span>
<span class="fc" id="L101">	}</span>

	/**
	 * Increase the verbosity of the stream by an amount.
	 * 
	 * @param amt
	 *            The amount to increase the verbosity by.
	 */
	public void louder(int amt) {
<span class="fc" id="L110">		verbosity += amt;</span>
<span class="fc" id="L111">	}</span>

	/**
	 * Decrement the verbosity of the stream.
	 */
	public void quieter() {
<span class="nc" id="L117">		quieter(1);</span>
<span class="nc" id="L118">	}</span>

	/**
	 * Decrease the verbosity of the stream by an amount.
	 * 
	 * @param amt
	 *            The amount to decrease the verbosity by.
	 */
	public void quieter(int amt) {
<span class="nc" id="L127">		verbosity -= amt;</span>
<span class="nc" id="L128">	}</span>

	/**
	 * Print a message that will always be visible.
	 *
	 * @param msg
	 *            The message to print.
	 */
	public void print(String msg) {
<span class="nc" id="L137">		output.print(msg);</span>
<span class="nc" id="L138">	}</span>

	/**
	 * Print a formatted message that will always be visible.
	 *
	 * @param msg
	 *             The format string for the message to print.
	 *
	 * @param args
	 *             The arguments to the format string.
	 */
	public void printf(String msg, Object... args) {
<span class="fc" id="L150">		output.printf(msg, args);</span>
<span class="fc" id="L151">	}</span>

	/**
	 * Print a message at a given verbosity level.
	 * 
	 * @param lvl
	 *            The verbosity level.
	 * @param msg
	 *            The message to print.
	 */
	public void message(int lvl, String msg) {
<span class="nc bnc" id="L162" title="All 2 branches missed.">		if (verbosity &gt;= lvl) {</span>
<span class="nc" id="L163">			output.print(msg);</span>
		}
<span class="nc" id="L165">	}</span>

	/**
	 * Print a formatted message at a given verbosity level.
	 * 
	 * @param lvl
	 *             The verbosity level.
	 * @param msg
	 *             The message to print.
	 * @param args
	 *             The arguments to the message.
	 */
	public void messagef(int lvl, String msg, Object... args) {
<span class="fc bfc" id="L178" title="All 2 branches covered.">		if (verbosity &gt;= lvl) {</span>
<span class="fc" id="L179">			output.printf(msg, args);</span>
		}
<span class="fc" id="L181">	}</span>

	/**
	 * Emit a fatal error message.
	 * 
	 * @param msg
	 *            The message to emit.
	 */
	public void fatal(String msg) {
<span class="nc" id="L190">		message(FATAL, msg);</span>
<span class="nc" id="L191">	}</span>

	/**
	 * Emit a formatted fatal error message.
	 * 
	 * @param msg
	 *             The message to emit.
	 * @param args
	 *             The arguments to the message.
	 */
	public void fatalf(String msg, Object... args) {
<span class="nc" id="L202">		messagef(FATAL, msg, args);</span>
<span class="nc" id="L203">	}</span>

	/**
	 * Emit a normal error message.
	 * 
	 * @param msg
	 *            The message to emit.
	 */
	public void error(String msg) {
<span class="nc" id="L212">		message(ERROR, msg);</span>
<span class="nc" id="L213">	}</span>

	/**
	 * Emit a formatted normal error message.
	 * 
	 * @param msg
	 *             The message to emit.
	 * @param args
	 *             The arguments to the message.
	 */
	public void errorf(String msg, Object... args) {
<span class="nc" id="L224">		messagef(ERROR, msg, args);</span>
<span class="nc" id="L225">	}</span>

	/**
	 * Emit a warning message.
	 * 
	 * @param msg
	 *            The message to emit.
	 */
	public void warn(String msg) {
<span class="nc" id="L234">		message(WARN, msg);</span>
<span class="nc" id="L235">	}</span>

	/**
	 * Emit a formatted warning message.
	 * 
	 * @param msg
	 *             The message to emit.
	 * @param args
	 *             The arguments to the message.
	 */
	public void warnf(String msg, Object... args) {
<span class="nc" id="L246">		messagef(WARN, msg, args);</span>
<span class="nc" id="L247">	}</span>

	/**
	 * Emit an info message.
	 * 
	 * @param msg
	 *            The message to emit.
	 */
	public void info(String msg) {
<span class="nc" id="L256">		message(INFO, msg);</span>
<span class="nc" id="L257">	}</span>

	/**
	 * Emit a formatted info message.
	 * 
	 * @param msg
	 *             The message to emit.
	 * @param args
	 *             The arguments to the message.
	 */
	public void infof(String msg, Object... args) {
<span class="fc" id="L268">		messagef(INFO, msg, args);</span>
<span class="fc" id="L269">	}</span>

	/**
	 * Emit a debug message.
	 * 
	 * @param msg
	 *            The message to emit.
	 */
	public void debug(String msg) {
<span class="nc" id="L278">		message(DEBUG, msg);</span>
<span class="nc" id="L279">	}</span>

	/**
	 * Emit a formatted debug message.
	 * 
	 * @param msg
	 *             The message to emit.
	 * @param args
	 *             The arguments to the message.
	 */
	public void debugf(String msg, Object... args) {
<span class="nc" id="L290">		messagef(DEBUG, msg, args);</span>
<span class="nc" id="L291">	}</span>

	/**
	 * Emit a tracing message.
	 * 
	 * @param msg
	 *            The message to emit.
	 */
	public void trace(String msg) {
<span class="nc" id="L300">		message(TRACE, msg);</span>
<span class="nc" id="L301">	}</span>

	/**
	 * Emit a formatted tracing message.
	 * 
	 * @param msg
	 *             The message to emit.
	 * @param args
	 *             The arguments to the message.
	 */
	public void tracef(String msg, Object... args) {
<span class="fc" id="L312">		messagef(TRACE, msg, args);</span>
<span class="fc" id="L313">	}</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.2.201808211720</span></div></body></html>