1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.util.internal.logging;
17
18 import io.netty5.util.internal.StringUtil;
19
20 import java.io.ObjectStreamException;
21 import java.io.Serializable;
22
23 import static java.util.Objects.requireNonNull;
24
25
26
27
28
29
30 public abstract class AbstractInternalLogger implements InternalLogger, Serializable {
31
32 private static final long serialVersionUID = -6382972526573193470L;
33
34 static final String EXCEPTION_MESSAGE = "Unexpected exception:";
35
36 private final String name;
37
38
39
40
41 protected AbstractInternalLogger(String name) {
42 requireNonNull(name, "name");
43 this.name = name;
44 }
45
46 @Override
47 public String name() {
48 return name;
49 }
50
51 @Override
52 public boolean isEnabled(InternalLogLevel level) {
53 switch (level) {
54 case TRACE:
55 return isTraceEnabled();
56 case DEBUG:
57 return isDebugEnabled();
58 case INFO:
59 return isInfoEnabled();
60 case WARN:
61 return isWarnEnabled();
62 case ERROR:
63 return isErrorEnabled();
64 default:
65 throw new Error();
66 }
67 }
68
69 @Override
70 public void trace(Throwable t) {
71 trace(EXCEPTION_MESSAGE, t);
72 }
73
74 @Override
75 public void debug(Throwable t) {
76 debug(EXCEPTION_MESSAGE, t);
77 }
78
79 @Override
80 public void info(Throwable t) {
81 info(EXCEPTION_MESSAGE, t);
82 }
83
84 @Override
85 public void warn(Throwable t) {
86 warn(EXCEPTION_MESSAGE, t);
87 }
88
89 @Override
90 public void error(Throwable t) {
91 error(EXCEPTION_MESSAGE, t);
92 }
93
94 @Override
95 public void log(InternalLogLevel level, String msg, Throwable cause) {
96 switch (level) {
97 case TRACE:
98 trace(msg, cause);
99 break;
100 case DEBUG:
101 debug(msg, cause);
102 break;
103 case INFO:
104 info(msg, cause);
105 break;
106 case WARN:
107 warn(msg, cause);
108 break;
109 case ERROR:
110 error(msg, cause);
111 break;
112 default:
113 throw new Error();
114 }
115 }
116
117 @Override
118 public void log(InternalLogLevel level, Throwable cause) {
119 switch (level) {
120 case TRACE:
121 trace(cause);
122 break;
123 case DEBUG:
124 debug(cause);
125 break;
126 case INFO:
127 info(cause);
128 break;
129 case WARN:
130 warn(cause);
131 break;
132 case ERROR:
133 error(cause);
134 break;
135 default:
136 throw new Error();
137 }
138 }
139
140 @Override
141 public void log(InternalLogLevel level, String msg) {
142 switch (level) {
143 case TRACE:
144 trace(msg);
145 break;
146 case DEBUG:
147 debug(msg);
148 break;
149 case INFO:
150 info(msg);
151 break;
152 case WARN:
153 warn(msg);
154 break;
155 case ERROR:
156 error(msg);
157 break;
158 default:
159 throw new Error();
160 }
161 }
162
163 @Override
164 public void log(InternalLogLevel level, String format, Object arg) {
165 switch (level) {
166 case TRACE:
167 trace(format, arg);
168 break;
169 case DEBUG:
170 debug(format, arg);
171 break;
172 case INFO:
173 info(format, arg);
174 break;
175 case WARN:
176 warn(format, arg);
177 break;
178 case ERROR:
179 error(format, arg);
180 break;
181 default:
182 throw new Error();
183 }
184 }
185
186 @Override
187 public void log(InternalLogLevel level, String format, Object argA, Object argB) {
188 switch (level) {
189 case TRACE:
190 trace(format, argA, argB);
191 break;
192 case DEBUG:
193 debug(format, argA, argB);
194 break;
195 case INFO:
196 info(format, argA, argB);
197 break;
198 case WARN:
199 warn(format, argA, argB);
200 break;
201 case ERROR:
202 error(format, argA, argB);
203 break;
204 default:
205 throw new Error();
206 }
207 }
208
209 @Override
210 public void log(InternalLogLevel level, String format, Object... arguments) {
211 switch (level) {
212 case TRACE:
213 trace(format, arguments);
214 break;
215 case DEBUG:
216 debug(format, arguments);
217 break;
218 case INFO:
219 info(format, arguments);
220 break;
221 case WARN:
222 warn(format, arguments);
223 break;
224 case ERROR:
225 error(format, arguments);
226 break;
227 default:
228 throw new Error();
229 }
230 }
231
232 protected Object readResolve() throws ObjectStreamException {
233 return InternalLoggerFactory.getInstance(name());
234 }
235
236 @Override
237 public String toString() {
238 return StringUtil.simpleClassName(this) + '(' + name() + ')';
239 }
240 }