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 package org.slf4j.cal10n;
26
27 import org.slf4j.Logger;
28 import org.slf4j.Marker;
29 import org.slf4j.MarkerFactory;
30 import org.slf4j.ext.LoggerWrapper;
31 import org.slf4j.spi.LocationAwareLogger;
32
33 import ch.qos.cal10n.IMessageConveyor;
34 import ch.qos.cal10n.MessageParameterObj;
35
36
37
38
39
40
41
42 public class LocLogger extends LoggerWrapper implements Logger {
43
44 private static final String FQCN = LocLogger.class.getName();
45
46
47
48
49
50
51 static Marker LOCALIZED = MarkerFactory.getMarker("LOCALIZED");
52
53 final IMessageConveyor imc;
54
55 public LocLogger(Logger logger, IMessageConveyor imc) {
56 super(logger, LoggerWrapper.class.getName());
57 if (imc == null) {
58 throw new IllegalArgumentException("IMessageConveyor cannot be null");
59 }
60 this.imc = imc;
61 }
62
63
64
65
66
67
68
69
70
71 public void trace(Enum<?> key, Object... args) {
72 if (!logger.isTraceEnabled()) {
73 return;
74 }
75 String translatedMsg = imc.getMessage(key, args);
76 MessageParameterObj mpo = new MessageParameterObj(key, args);
77
78 if (instanceofLAL) {
79 ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.TRACE_INT, translatedMsg, args, null);
80 } else {
81 logger.trace(LOCALIZED, translatedMsg, mpo);
82 }
83 }
84
85
86
87
88
89
90
91
92
93 public void debug(Enum<?> key, Object... args) {
94 if (!logger.isDebugEnabled()) {
95 return;
96 }
97 String translatedMsg = imc.getMessage(key, args);
98 MessageParameterObj mpo = new MessageParameterObj(key, args);
99
100 if (instanceofLAL) {
101 ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.DEBUG_INT, translatedMsg, args, null);
102 } else {
103 logger.debug(LOCALIZED, translatedMsg, mpo);
104 }
105 }
106
107
108
109
110
111
112
113
114
115 public void info(Enum<?> key, Object... args) {
116 if (!logger.isInfoEnabled()) {
117 return;
118 }
119 String translatedMsg = imc.getMessage(key, args);
120 MessageParameterObj mpo = new MessageParameterObj(key, args);
121
122 if (instanceofLAL) {
123 ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.INFO_INT, translatedMsg, args, null);
124 } else {
125 logger.info(LOCALIZED, translatedMsg, mpo);
126 }
127 }
128
129
130
131
132
133
134
135
136
137 public void warn(Enum<?> key, Object... args) {
138 if (!logger.isWarnEnabled()) {
139 return;
140 }
141 String translatedMsg = imc.getMessage(key, args);
142 MessageParameterObj mpo = new MessageParameterObj(key, args);
143
144 if (instanceofLAL) {
145 ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.WARN_INT, translatedMsg, args, null);
146 } else {
147 logger.warn(LOCALIZED, translatedMsg, mpo);
148 }
149 }
150
151
152
153
154
155
156
157
158
159 public void error(Enum<?> key, Object... args) {
160 if (!logger.isErrorEnabled()) {
161 return;
162 }
163 String translatedMsg = imc.getMessage(key, args);
164 MessageParameterObj mpo = new MessageParameterObj(key, args);
165
166 if (instanceofLAL) {
167 ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.ERROR_INT, translatedMsg, args, null);
168 } else {
169 logger.error(LOCALIZED, translatedMsg, mpo);
170 }
171 }
172
173 }