comparison src/org/tn5250j/tools/logging/Log4jLogger.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 * @(#)Log4jLogger.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 import org.apache.log4j.Level;
26 import org.apache.log4j.Logger;
27
28 /**
29 * An implementation of the TN5250jLogger to provide log4j logger instances.
30 */
31 public final class Log4jLogger implements TN5250jLogger {
32
33 private Logger log = null;
34
35 /*
36 * Package level access only
37 */
38 Log4jLogger() {
39
40 }
41
42 public void initialize(final String clazz) {
43 log = Logger.getLogger(clazz);
44 }
45
46 public void debug(Object message) {
47 log.debug(message);
48 }
49
50 public void debug(Object message, Throwable throwable) {
51 log.debug(message, throwable);
52 }
53
54 public void info(Object message) {
55 log.info(message);
56 }
57
58 public void info(Object message, Throwable throwable) {
59 log.info(message, throwable);
60 }
61
62 public void warn(Object message) {
63 log.warn(message);
64 }
65
66 public void warn(Object message, Throwable throwable) {
67 log.warn(message, throwable);
68 }
69
70 public void error(Object message) {
71 log.error(message);
72 }
73
74 public void error(Object message, Throwable throwable) {
75 log.error(message, throwable);
76 }
77
78 public void fatal(Object message) {
79 log.fatal(message);
80 }
81
82 public void fatal(Object message, Throwable throwable) {
83 log.fatal(message, throwable);
84 }
85
86 public boolean isDebugEnabled() {
87 return log.isDebugEnabled();
88 }
89
90 public boolean isInfoEnabled() {
91 return log.isInfoEnabled();
92 }
93
94 public boolean isWarnEnabled() {
95 return (Level.WARN.equals(log.getLevel()));
96 }
97
98 public boolean isFatalEnabled() {
99 return (Level.FATAL.equals(log.getLevel()));
100 }
101
102 public boolean isErrorEnabled() {
103 return (Level.ERROR.equals(log.getLevel()));
104 }
105
106 public void setLevel(int newLevel) {
107
108 switch (newLevel) {
109 case OFF:
110 log.setLevel(Level.OFF);
111 break;
112
113 case DEBUG:
114 log.setLevel(Level.DEBUG);
115 break;
116
117 case INFO:
118 log.setLevel(Level.INFO);
119 break;
120
121 case WARN:
122 log.setLevel(Level.WARN);
123 break;
124
125 case ERROR:
126 log.setLevel(Level.ERROR);
127 break;
128
129 case FATAL:
130 log.setLevel(Level.FATAL);
131 break;
132 }
133
134 }
135
136 public int getLevel() {
137
138 switch (log.getLevel().toInt()) {
139
140 case (org.apache.log4j.Level.DEBUG_INT):
141 return DEBUG;
142
143 case (org.apache.log4j.Level.INFO_INT):
144 return INFO;
145
146 case (org.apache.log4j.Level.WARN_INT):
147 return WARN;
148
149 case (org.apache.log4j.Level.ERROR_INT):
150 return ERROR;
151
152 case (org.apache.log4j.Level.FATAL_INT):
153 return FATAL;
154 default:
155 return WARN;
156 }
157
158 }
159 }