1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+
18+ package io .microsphere .logging .log4j ;
19+
20+ import io .microsphere .lang .DelegatingWrapper ;
21+ import io .microsphere .logging .AbstractLogger ;
22+ import org .apache .log4j .Logger ;
23+
24+ import static io .microsphere .logging .log4j .util .LoggerUtils .getLogger ;
25+ import static org .apache .log4j .Level .ERROR ;
26+ import static org .apache .log4j .Level .WARN ;
27+
28+ /**
29+ * The Logger adapter class based Log4j {@link Logger}
30+ *
31+ * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
32+ * @see AbstractLogger
33+ * @see Logger
34+ * @since 1.0.0
35+ */
36+ class Log4j2Logger extends AbstractLogger implements DelegatingWrapper {
37+
38+ private final Logger logger ;
39+
40+ public Log4j2Logger (String loggerName ) {
41+ super (loggerName );
42+ this .logger = getLogger (loggerName );
43+ }
44+
45+ @ Override
46+ public boolean isTraceEnabled () {
47+ return this .logger .isTraceEnabled ();
48+ }
49+
50+ @ Override
51+ public void trace (String message ) {
52+ this .logger .trace (message );
53+ }
54+
55+ @ Override
56+ public void trace (String message , Throwable t ) {
57+ this .logger .trace (message , t );
58+ }
59+
60+ @ Override
61+ public boolean isDebugEnabled () {
62+ return this .logger .isDebugEnabled ();
63+ }
64+
65+ @ Override
66+ public void debug (String message ) {
67+ this .logger .debug (message );
68+
69+ }
70+
71+ @ Override
72+ public void debug (String message , Throwable t ) {
73+ this .logger .debug (message , t );
74+ }
75+
76+ @ Override
77+ public boolean isInfoEnabled () {
78+ return this .logger .isInfoEnabled ();
79+ }
80+
81+ @ Override
82+ public void info (String message ) {
83+ this .logger .info (message );
84+ }
85+
86+ @ Override
87+ public void info (String message , Throwable t ) {
88+ this .logger .info (message , t );
89+ }
90+
91+ @ Override
92+ public boolean isWarnEnabled () {
93+ return this .logger .isEnabledFor (WARN );
94+ }
95+
96+ @ Override
97+ public void warn (String message ) {
98+ this .logger .warn (message );
99+ }
100+
101+ @ Override
102+ public void warn (String message , Throwable t ) {
103+ this .logger .warn (message , t );
104+ }
105+
106+ @ Override
107+ public boolean isErrorEnabled () {
108+ return this .logger .isEnabledFor (ERROR );
109+ }
110+
111+ @ Override
112+ public void error (String message ) {
113+ this .logger .error (message );
114+ }
115+
116+ @ Override
117+ public void error (String message , Throwable t ) {
118+ this .logger .error (message , t );
119+ }
120+
121+ @ Override
122+ public Object getDelegate () {
123+ return this .logger ;
124+ }
125+ }
0 commit comments