01: /**
02: * Copyright (c) 2007, Aberystwyth University
03: *
04: * All rights reserved.
05: *
06: * Redistribution and use in source and binary forms, with or without
07: * modification, are permitted provided that the following conditions
08: * are met:
09: *
10: * - Redistributions of source code must retain the above
11: * copyright notice, this list of conditions and the
12: * following disclaimer.
13: *
14: * - Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in
16: * the documentation and/or other materials provided with the
17: * distribution.
18: *
19: * - Neither the name of the Centre for Advanced Software and
20: * Intelligent Systems (CASIS) nor the names of its
21: * contributors may be used to endorse or promote products derived
22: * from this software without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
32: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
34: * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35: * SUCH DAMAGE.
36: */package org.purl.sword.base;
37:
38: /**
39: * Author : $Author: nst $
40: * Date : $Date: 2007/09/21 15:18:55 $
41: * Revision : $Revision: 1.3 $
42: * Name : $Name: $
43: */
44:
45: /**
46: *
47: */
48: public class InfoLogger {
49: /**
50: * Single instance of the InfoLogger that can be used by all
51: * calling classes.
52: */
53: private static InfoLogger logger = null;
54:
55: /**
56: * Set the default level to ERROR messages only.
57: */
58: private InfoLoggerLevel level = InfoLoggerLevel.ERROR;
59:
60: /**
61: *
62: */
63: public void setLevel(InfoLoggerLevel level) {
64: this .level = level;
65: }
66:
67: /**
68: * Returns the single instance of this class. If this is the first call,
69: * the logger is created on this call.
70: *
71: * @return The InfoLogger.
72: */
73: public static InfoLogger getLogger() {
74: if (logger == null) {
75: logger = new InfoLogger();
76: }
77: return logger;
78: }
79:
80: public void writeError(String message) {
81: // always log errors
82: System.err.println("Error: " + message);
83: }
84:
85: public void writeInfo(String message) {
86: if (level == InfoLoggerLevel.ERROR_WARNING_INFO) {
87: System.err.println("Info: " + message);
88: }
89: }
90:
91: public void writeWarning(String message) {
92: if (level != InfoLoggerLevel.ERROR) {
93: System.err.println("Warning: " + message);
94: }
95: }
96: }
|