comparison src/org/tn5250j/tools/logging/ConsoleLogger.java @ 5:cbdff98c45ea tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 12:38:09 -0700
parents
children
comparison
equal deleted inserted replaced
4:1f5d9b76a183 5:cbdff98c45ea
1 /*
2 * @(#)ConsoleLogger.java
3 * @author Kenneth J. Pouncey
4 *
5 * Copyright: Copyright (c) 2001, 2002, 2003
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this software; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
21 *
22 */
23 package org.tn5250j.tools.logging;
24
25 /**
26 * An implementation of the TN5250jLogger to provide logger instances to the
27 * console - System.out or System.err.
28 */
29 public final class ConsoleLogger implements TN5250jLogger {
30
31 private int logLevel = TN5250jLogger.WARN;
32
33 private String clazz = null;
34
35 /*
36 * Package level access only
37 */
38 ConsoleLogger() {
39
40 }
41
42 public void initialize(final String clazz) {
43 this.clazz = clazz;
44 }
45
46 public void debug(Object message) {
47 if (isDebugEnabled())
48 System.out.println("DEBUG [" + clazz + "] " + ((message!=null) ? message.toString() : ""));
49 }
50
51 public void debug(Object message, Throwable throwable) {
52 if (isDebugEnabled())
53 System.out.println("DEBUG [" + clazz + "] "
54 + ((message!=null) ? message.toString() : "")
55 + ((throwable!=null) ? throwable.getMessage() : ""));
56 }
57
58 public void info(Object message) {
59 if (isInfoEnabled())
60 System.out.println("INFO [" + clazz + "] " + ((message!=null) ? message.toString() : ""));
61 }
62
63 public void info(Object message, Throwable throwable) {
64 if (isInfoEnabled())
65 System.out.println("INFO [" + clazz + "] "
66 + ((message!=null) ? message.toString() : "")
67 + ((throwable!=null) ? throwable.getMessage() : ""));
68 }
69
70 public void warn(Object message) {
71 if (isWarnEnabled())
72 System.err.println("WARN [" + clazz + "] " + ((message!=null) ? message.toString() : ""));
73 }
74
75 public void warn(Object message, Throwable throwable) {
76 if (isWarnEnabled())
77 System.err.println("WARN [" + clazz + "] "
78 + ((message!=null) ? message.toString() : "")
79 + ((throwable!=null) ? throwable.getMessage() : ""));
80 }
81
82 public void error(Object message) {
83 if (isErrorEnabled())
84 System.err.println("ERROR [" + clazz + "] " + ((message!=null) ? message.toString() : ""));
85 }
86
87 public void error(Object message, Throwable throwable) {
88 if (isErrorEnabled())
89 System.err.println("ERROR [" + clazz + "] "
90 + ((message!=null) ? message.toString() : "")
91 + ((throwable!=null) ? throwable.getMessage() : ""));
92 }
93
94 public void fatal(Object message) {
95 if (isFatalEnabled())
96 System.err.println("FATAL [" + clazz + "] " + ((message!=null) ? message.toString() : ""));
97 }
98
99 public void fatal(Object message, Throwable throwable) {
100 if (isFatalEnabled())
101 System.err.println("FATAL [" + clazz + "] "
102 + ((message!=null) ? message.toString() : "")
103 + ((throwable!=null) ? throwable.getMessage() : ""));
104 }
105
106 public boolean isDebugEnabled() {
107 return (logLevel <= DEBUG); // 1
108 }
109
110 public boolean isInfoEnabled() {
111 return (logLevel <= INFO); // 2
112 }
113
114 public boolean isWarnEnabled() {
115 return (logLevel <= WARN); // 4
116 }
117
118 public boolean isErrorEnabled() {
119 return (logLevel <= ERROR); // 8
120 }
121
122 public boolean isFatalEnabled() {
123 return (logLevel <= FATAL); // 16
124 }
125
126 public int getLevel() {
127 return logLevel;
128 }
129
130 public void setLevel(int newLevel) {
131 logLevel = newLevel;
132 }
133
134 }