Skip to content

Commit 3fdab36

Browse files
committed
AbstractLogService: refactor level check logic
We do the level check in the level-specific methods now, in preparation for the protected log(int level, Object msg, Throwable t) method to become the central override point of concrete implementations. That way, specific implementations will not need to worry about filtering based on level in the typical case.
1 parent 188201f commit 3fdab36

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/main/java/org/scijava/log/AbstractLogService.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ public AbstractLogService() {
9999
// -- helper methods --
100100

101101
protected void log(final int level, final Object msg, final Throwable t) {
102-
if (level > getLevel()) return;
103-
104102
if (msg != null || t == null) {
105103
log(level, msg);
106104
}
@@ -116,77 +114,77 @@ protected void log(final int level, final Object msg) {
116114

117115
@Override
118116
public void debug(final Object msg) {
119-
log(DEBUG, msg, null);
117+
if (isDebug()) log(DEBUG, msg, null);
120118
}
121119

122120
@Override
123121
public void debug(final Throwable t) {
124-
log(DEBUG, null, t);
122+
if (isDebug()) log(DEBUG, null, t);
125123
}
126124

127125
@Override
128126
public void debug(final Object msg, final Throwable t) {
129-
log(DEBUG, msg, t);
127+
if (isDebug()) log(DEBUG, msg, t);
130128
}
131129

132130
@Override
133131
public void error(final Object msg) {
134-
log(ERROR, msg, null);
132+
if (isError()) log(ERROR, msg, null);
135133
}
136134

137135
@Override
138136
public void error(final Throwable t) {
139-
log(ERROR, null, t);
137+
if (isError()) log(ERROR, null, t);
140138
}
141139

142140
@Override
143141
public void error(final Object msg, final Throwable t) {
144-
log(ERROR, msg, t);
142+
if (isError()) log(ERROR, msg, t);
145143
}
146144

147145
@Override
148146
public void info(final Object msg) {
149-
log(INFO, msg, null);
147+
if (isInfo()) log(INFO, msg, null);
150148
}
151149

152150
@Override
153151
public void info(final Throwable t) {
154-
log(INFO, null, t);
152+
if (isInfo()) log(INFO, null, t);
155153
}
156154

157155
@Override
158156
public void info(final Object msg, final Throwable t) {
159-
log(INFO, msg, t);
157+
if (isInfo()) log(INFO, msg, t);
160158
}
161159

162160
@Override
163161
public void trace(final Object msg) {
164-
log(TRACE, msg, null);
162+
if (isTrace()) log(TRACE, msg, null);
165163
}
166164

167165
@Override
168166
public void trace(final Throwable t) {
169-
log(TRACE, null, t);
167+
if (isTrace()) log(TRACE, null, t);
170168
}
171169

172170
@Override
173171
public void trace(final Object msg, final Throwable t) {
174-
log(TRACE, msg, t);
172+
if (isTrace()) log(TRACE, msg, t);
175173
}
176174

177175
@Override
178176
public void warn(final Object msg) {
179-
log(WARN, msg, null);
177+
if (isWarn()) log(WARN, msg, null);
180178
}
181179

182180
@Override
183181
public void warn(final Throwable t) {
184-
log(WARN, null, t);
182+
if (isWarn()) log(WARN, null, t);
185183
}
186184

187185
@Override
188186
public void warn(final Object msg, final Throwable t) {
189-
log(WARN, msg, t);
187+
if (isWarn()) log(WARN, msg, t);
190188
}
191189

192190
@Override

0 commit comments

Comments
 (0)