Skip to content

Commit c53dfb8

Browse files
committed
Prevent log event creation of disabled levels
1 parent 7881796 commit c53dfb8

1 file changed

Lines changed: 100 additions & 25 deletions

File tree

‎api/src/main/java/org/ocpsoft/logging/Logger.java‎

Lines changed: 100 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,42 @@ public boolean isTraceEnabled()
3333

3434
public void trace(final String msg)
3535
{
36-
log(Level.TRACE, msg, null);
36+
if (isTraceEnabled())
37+
{
38+
log(Level.TRACE, msg, null);
39+
}
3740
}
3841

3942
public void trace(final String msg, final Object arg)
4043
{
41-
log(Level.TRACE, format(msg, new Object[] { arg }), null);
44+
if (isTraceEnabled())
45+
{
46+
log(Level.TRACE, format(msg, new Object[] { arg }), null);
47+
}
4248
}
4349

4450
public void trace(final String msg, final Object arg1, final Object arg2)
4551
{
46-
log(Level.TRACE, format(msg, new Object[] { arg1, arg2 }), null);
52+
if (isTraceEnabled())
53+
{
54+
log(Level.TRACE, format(msg, new Object[] { arg1, arg2 }), null);
55+
}
4756
}
4857

4958
public void trace(final String msg, final Object[] argArray)
5059
{
51-
log(Level.TRACE, format(msg, argArray), null);
60+
if (isTraceEnabled())
61+
{
62+
log(Level.TRACE, format(msg, argArray), null);
63+
}
5264
}
5365

5466
public void trace(final String msg, final Throwable t)
5567
{
56-
log(Level.TRACE, msg, t);
68+
if (isTraceEnabled())
69+
{
70+
log(Level.TRACE, msg, t);
71+
}
5772
}
5873

5974
public boolean isDebugEnabled()
@@ -63,27 +78,42 @@ public boolean isDebugEnabled()
6378

6479
public void debug(final String msg)
6580
{
66-
log(Level.DEBUG, msg, null);
81+
if (isDebugEnabled())
82+
{
83+
log(Level.DEBUG, msg, null);
84+
}
6785
}
6886

6987
public void debug(final String msg, final Object arg)
7088
{
71-
log(Level.DEBUG, format(msg, new Object[] { arg }), null);
89+
if (isDebugEnabled())
90+
{
91+
log(Level.DEBUG, format(msg, new Object[] { arg }), null);
92+
}
7293
}
7394

7495
public void debug(final String msg, final Object arg1, final Object arg2)
7596
{
76-
log(Level.DEBUG, format(msg, new Object[] { arg1, arg2 }), null);
97+
if (isDebugEnabled())
98+
{
99+
log(Level.DEBUG, format(msg, new Object[] { arg1, arg2 }), null);
100+
}
77101
}
78102

79103
public void debug(final String msg, final Object[] argArray)
80104
{
81-
log(Level.DEBUG, format(msg, argArray), null);
105+
if (isDebugEnabled())
106+
{
107+
log(Level.DEBUG, format(msg, argArray), null);
108+
}
82109
}
83110

84111
public void debug(final String msg, final Throwable t)
85112
{
86-
log(Level.DEBUG, msg, t);
113+
if (isDebugEnabled())
114+
{
115+
log(Level.DEBUG, msg, t);
116+
}
87117
}
88118

89119
public boolean isInfoEnabled()
@@ -93,27 +123,42 @@ public boolean isInfoEnabled()
93123

94124
public void info(final String msg)
95125
{
96-
log(Level.INFO, msg, null);
126+
if (isInfoEnabled())
127+
{
128+
log(Level.INFO, msg, null);
129+
}
97130
}
98131

99132
public void info(final String msg, final Object arg)
100133
{
101-
log(Level.INFO, format(msg, new Object[] { arg }), null);
134+
if (isInfoEnabled())
135+
{
136+
log(Level.INFO, format(msg, new Object[] { arg }), null);
137+
}
102138
}
103139

104140
public void info(final String msg, final Object arg1, final Object arg2)
105141
{
106-
log(Level.INFO, format(msg, new Object[] { arg1, arg2 }), null);
142+
if (isInfoEnabled())
143+
{
144+
log(Level.INFO, format(msg, new Object[] { arg1, arg2 }), null);
145+
}
107146
}
108147

109148
public void info(final String msg, final Object[] argArray)
110149
{
111-
log(Level.INFO, format(msg, argArray), null);
150+
if (isInfoEnabled())
151+
{
152+
log(Level.INFO, format(msg, argArray), null);
153+
}
112154
}
113155

114156
public void info(final String msg, final Throwable t)
115157
{
116-
log(Level.INFO, msg, t);
158+
if (isInfoEnabled())
159+
{
160+
log(Level.INFO, msg, t);
161+
}
117162
}
118163

119164
public boolean isWarnEnabled()
@@ -123,27 +168,42 @@ public boolean isWarnEnabled()
123168

124169
public void warn(final String msg)
125170
{
126-
log(Level.WARN, msg, null);
171+
if (isWarnEnabled())
172+
{
173+
log(Level.WARN, msg, null);
174+
}
127175
}
128176

129177
public void warn(final String msg, final Object arg)
130178
{
131-
log(Level.WARN, format(msg, new Object[] { arg }), null);
179+
if (isWarnEnabled())
180+
{
181+
log(Level.WARN, format(msg, new Object[] { arg }), null);
182+
}
132183
}
133184

134185
public void warn(final String msg, final Object arg1, final Object arg2)
135186
{
136-
log(Level.WARN, format(msg, new Object[] { arg1, arg2 }), null);
187+
if (isWarnEnabled())
188+
{
189+
log(Level.WARN, format(msg, new Object[] { arg1, arg2 }), null);
190+
}
137191
}
138192

139193
public void warn(final String msg, final Object[] argArray)
140194
{
141-
log(Level.WARN, format(msg, argArray), null);
195+
if (isWarnEnabled())
196+
{
197+
log(Level.WARN, format(msg, argArray), null);
198+
}
142199
}
143200

144201
public void warn(final String msg, final Throwable t)
145202
{
146-
log(Level.WARN, msg, t);
203+
if (isWarnEnabled())
204+
{
205+
log(Level.WARN, msg, t);
206+
}
147207
}
148208

149209
public boolean isErrorEnabled()
@@ -153,27 +213,42 @@ public boolean isErrorEnabled()
153213

154214
public void error(final String msg)
155215
{
156-
log(Level.ERROR, msg, null);
216+
if (isErrorEnabled())
217+
{
218+
log(Level.ERROR, msg, null);
219+
}
157220
}
158221

159222
public void error(final String msg, final Object arg)
160223
{
161-
log(Level.ERROR, format(msg, new Object[] { arg }), null);
224+
if (isErrorEnabled())
225+
{
226+
log(Level.ERROR, format(msg, new Object[] { arg }), null);
227+
}
162228
}
163229

164230
public void error(final String msg, final Object arg1, final Object arg2)
165231
{
166-
log(Level.ERROR, format(msg, new Object[] { arg1, arg2 }), null);
232+
if (isErrorEnabled())
233+
{
234+
log(Level.ERROR, format(msg, new Object[] { arg1, arg2 }), null);
235+
}
167236
}
168237

169238
public void error(final String msg, final Object[] argArray)
170239
{
171-
log(Level.ERROR, format(msg, argArray), null);
240+
if (isErrorEnabled())
241+
{
242+
log(Level.ERROR, format(msg, argArray), null);
243+
}
172244
}
173245

174246
public void error(final String msg, final Throwable t)
175247
{
176-
log(Level.ERROR, msg, t);
248+
if (isErrorEnabled())
249+
{
250+
log(Level.ERROR, msg, t);
251+
}
177252
}
178253

179254
protected String format(final String msg, final Object[] args)

0 commit comments

Comments
 (0)