View | Details | Raw Unified | Return to bug 59777
Collapse All | Expand All

(-)a/src/core/org/apache/jmeter/logging/LogkitLoggerAdapter.java (-341 lines)
Lines 1-341 Link Here
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
19
package org.apache.jmeter.logging;
20
21
import java.io.Serializable;
22
23
import org.apache.log.Logger;
24
import org.apache.log.Priority;
25
import org.slf4j.helpers.FormattingTuple;
26
import org.slf4j.helpers.MarkerIgnoringBase;
27
import org.slf4j.helpers.MessageFormatter;
28
29
/**
30
 * Logkit adapter for slf4j 
31
 * @since 3.0
32
 */
33
public class LogkitLoggerAdapter extends MarkerIgnoringBase implements Serializable {
34
35
    final transient Logger logger;
36
37
    private static final long serialVersionUID = -122848886791823355L;
38
39
    /**
40
     * @deprecated Only for use by JUnit
41
     */
42
    @Deprecated // only for Unit test usage
43
    public LogkitLoggerAdapter() {
44
        super();
45
        this.logger = null;
46
    }
47
    
48
    LogkitLoggerAdapter(org.apache.log.Logger logkitLogger) {
49
        this.logger = logkitLogger;
50
    }
51
52
    /* (non-Javadoc)
53
     * @see org.slf4j.Logger#debug(java.lang.String)
54
     */
55
    @Override
56
    public void debug(String msg) {
57
        logger.debug(msg);
58
    }
59
60
    /* (non-Javadoc)
61
     * @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object)
62
     */
63
    @Override
64
    public void debug(String format, Object arg) {
65
        if (logger.isDebugEnabled()) {
66
            FormattingTuple ft = MessageFormatter.format(format, arg);
67
            logger.log(Priority.DEBUG, ft.getMessage(), ft.getThrowable());
68
        }
69
    }
70
71
    /* (non-Javadoc)
72
     * @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object[])
73
     */
74
    @Override
75
    public void debug(String format, Object... args) {
76
        if (logger.isDebugEnabled()) {
77
            FormattingTuple ft = MessageFormatter.format(format, args);
78
            logger.log(Priority.DEBUG, ft.getMessage(), ft.getThrowable());
79
        }
80
    }
81
82
    /* (non-Javadoc)
83
     * @see org.slf4j.Logger#debug(java.lang.String, java.lang.Throwable)
84
     */
85
    @Override
86
    public void debug(String msg, Throwable throwable) {
87
        if (logger.isDebugEnabled()) {
88
            logger.log(Priority.DEBUG, msg, throwable);
89
        }
90
    }
91
92
    /* (non-Javadoc)
93
     * @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object, java.lang.Object)
94
     */
95
    @Override
96
    public void debug(String format, Object arg1, Object arg2) {
97
        if (logger.isDebugEnabled()) {
98
            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
99
            logger.log(Priority.DEBUG, ft.getMessage(), ft.getThrowable());
100
        }
101
    }
102
103
    /* (non-Javadoc)
104
     * @see org.slf4j.Logger#error(java.lang.String)
105
     */
106
    @Override
107
    public void error(String message) {
108
        if (logger.isErrorEnabled()) {
109
            logger.log(Priority.ERROR, message);
110
        }
111
    }
112
113
    /* (non-Javadoc)
114
     * @see org.slf4j.Logger#error(java.lang.String, java.lang.Object)
115
     */
116
    @Override
117
    public void error(String format, Object arg) {
118
        if (logger.isErrorEnabled()) {
119
            FormattingTuple ft = MessageFormatter.format(format, arg);
120
            logger.log(Priority.ERROR, ft.getMessage(), ft.getThrowable());
121
        }
122
    }
123
124
    /* (non-Javadoc)
125
     * @see org.slf4j.Logger#error(java.lang.String, java.lang.Object[])
126
     */
127
    @Override
128
    public void error(String format, Object... args) {
129
        if (logger.isErrorEnabled()) {
130
            FormattingTuple ft = MessageFormatter.format(format, args);
131
            logger.log(Priority.ERROR, ft.getMessage(), ft.getThrowable());
132
        }
133
    }
134
135
    /* (non-Javadoc)
136
     * @see org.slf4j.Logger#error(java.lang.String, java.lang.Throwable)
137
     */
138
    @Override
139
    public void error(String message, Throwable throwable) {
140
        if (logger.isErrorEnabled()) {
141
            logger.log(Priority.ERROR, message, throwable);
142
        }
143
    }
144
145
    /* (non-Javadoc)
146
     * @see org.slf4j.Logger#error(java.lang.String, java.lang.Object, java.lang.Object)
147
     */
148
    @Override
149
    public void error(String format, Object arg1, Object arg2) {
150
        if (logger.isErrorEnabled()) {
151
            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
152
            logger.log(Priority.ERROR, ft.getMessage(), ft.getThrowable());
153
        }
154
    }
155
156
    /* (non-Javadoc)
157
     * @see org.slf4j.Logger#info(java.lang.String)
158
     */
159
    @Override
160
    public void info(String message) {
161
        if (logger.isInfoEnabled()) {
162
            logger.log(Priority.INFO, message);
163
        }
164
    }
165
166
    /* (non-Javadoc)
167
     * @see org.slf4j.Logger#info(java.lang.String, java.lang.Object)
168
     */
169
    @Override
170
    public void info(String format, Object arg1) {
171
        if (logger.isInfoEnabled()) {
172
            FormattingTuple ft = MessageFormatter.format(format, arg1);
173
            logger.log(Priority.INFO, ft.getMessage(), ft.getThrowable());
174
        }
175
    }
176
177
    /* (non-Javadoc)
178
     * @see org.slf4j.Logger#info(java.lang.String, java.lang.Object[])
179
     */
180
    @Override
181
    public void info(String format, Object... args) {
182
        if (logger.isInfoEnabled()) {
183
            FormattingTuple ft = MessageFormatter.format(format, args);
184
            logger.log(Priority.INFO, ft.getMessage(), ft.getThrowable());
185
        }
186
    }
187
188
    /* (non-Javadoc)
189
     * @see org.slf4j.Logger#info(java.lang.String, java.lang.Throwable)
190
     */
191
    @Override
192
    public void info(String message, Throwable throwable) {
193
        if (logger.isInfoEnabled()) {
194
            logger.log(Priority.INFO, message, throwable);
195
        }
196
    }
197
198
    /* (non-Javadoc)
199
     * @see org.slf4j.Logger#info(java.lang.String, java.lang.Object, java.lang.Object)
200
     */
201
    @Override
202
    public void info(String format, Object arg1, Object arg2) {
203
        if (logger.isInfoEnabled()) {
204
            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
205
            logger.log(Priority.INFO, ft.getMessage(), ft.getThrowable());
206
        }
207
    }
208
209
    /* (non-Javadoc)
210
     * @see org.slf4j.Logger#isDebugEnabled()
211
     */
212
    @Override
213
    public boolean isDebugEnabled() {
214
        return logger.isDebugEnabled();
215
    }
216
217
    /* (non-Javadoc)
218
     * @see org.slf4j.Logger#isErrorEnabled()
219
     */
220
    @Override
221
    public boolean isErrorEnabled() {
222
        return logger.isErrorEnabled();
223
    }
224
225
    /* (non-Javadoc)
226
     * @see org.slf4j.Logger#isInfoEnabled()
227
     */
228
    @Override
229
    public boolean isInfoEnabled() {
230
        return logger.isInfoEnabled();
231
    }
232
233
    /* (non-Javadoc)
234
     * @see org.slf4j.Logger#isTraceEnabled()
235
     */
236
    @Override
237
    public boolean isTraceEnabled() {
238
        return logger.isDebugEnabled();
239
    }
240
241
    /* (non-Javadoc)
242
     * @see org.slf4j.Logger#isWarnEnabled()
243
     */
244
    @Override
245
    public boolean isWarnEnabled() {
246
        return logger.isWarnEnabled();
247
    }
248
249
    /* (non-Javadoc)
250
     * @see org.slf4j.Logger#warn(java.lang.String)
251
     */
252
    @Override
253
    public void warn(String message) {
254
        if (logger.isWarnEnabled()) {
255
            logger.log(Priority.WARN, message);
256
        }
257
    }
258
259
    /* (non-Javadoc)
260
     * @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object)
261
     */
262
    @Override
263
    public void warn(String format, Object arg) {
264
        if (logger.isWarnEnabled()) {
265
            FormattingTuple ft = MessageFormatter.format(format, arg);
266
            logger.log(Priority.WARN, ft.getMessage(), ft.getThrowable());
267
        }
268
    }
269
270
    /* (non-Javadoc)
271
     * @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object[])
272
     */
273
    @Override
274
    public void warn(String format, Object... args) {
275
        if (logger.isWarnEnabled()) {
276
            FormattingTuple ft = MessageFormatter.format(format, args);
277
            logger.log(Priority.WARN, ft.getMessage(), ft.getThrowable());
278
        }
279
    }
280
281
    /* (non-Javadoc)
282
     * @see org.slf4j.Logger#warn(java.lang.String, java.lang.Throwable)
283
     */
284
    @Override
285
    public void warn(String message, Throwable throwable) {
286
        if (logger.isWarnEnabled()) {
287
            logger.log(Priority.WARN, message, throwable);
288
        }
289
    }
290
291
    /* (non-Javadoc)
292
     * @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object, java.lang.Object)
293
     */
294
    @Override
295
    public void warn(String format, Object arg1, Object arg2) {
296
        if (logger.isWarnEnabled()) {
297
            FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
298
            logger.log(Priority.WARN, ft.getMessage(), ft.getThrowable());
299
        }
300
    }
301
302
    /* (non-Javadoc)
303
     * @see org.slf4j.Logger#trace(java.lang.String)
304
     */
305
    @Override
306
    public void trace(String message) {
307
        debug(message);
308
    }
309
310
    /* (non-Javadoc)
311
     * @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object)
312
     */
313
    @Override
314
    public void trace(String format, Object arg) {
315
        debug(format, arg);
316
    }
317
318
    /* (non-Javadoc)
319
     * @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object[])
320
     */
321
    @Override
322
    public void trace(String format, Object... args) {
323
        debug(format, args);
324
    }
325
326
    /* (non-Javadoc)
327
     * @see org.slf4j.Logger#trace(java.lang.String, java.lang.Throwable)
328
     */
329
    @Override
330
    public void trace(String message, Throwable throwable) {
331
        debug(message, throwable);
332
    }
333
334
    /* (non-Javadoc)
335
     * @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object, java.lang.Object)
336
     */
337
    @Override
338
    public void trace(String format, Object arg1, Object arg2) {
339
        debug(format, arg1, arg2);
340
    }
341
}
(-)a/src/core/org/apache/jmeter/logging/LogkitLoggerFactory.java (-70 lines)
Lines 1-70 Link Here
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
19
package org.apache.jmeter.logging;
20
21
import java.util.HashMap;
22
import java.util.Map;
23
24
import org.apache.jorphan.logging.LoggingManager;
25
import org.apache.log.Hierarchy;
26
import org.slf4j.ILoggerFactory;
27
import org.slf4j.Logger;
28
29
/**
30
 * Implementation of {@link ILoggerFactory} for Logkit
31
 * @since 3.0
32
 */
33
public class LogkitLoggerFactory implements ILoggerFactory {
34
    // key: name (String), value: a Log4jLogger;
35
    private final Map<String, Logger> loggerMap;
36
37
    /**
38
     * 
39
     */
40
    public LogkitLoggerFactory() {
41
        loggerMap = new HashMap<>();
42
    }
43
44
    /**
45
     * 
46
     * @see org.slf4j.ILoggerFactory#getLogger(java.lang.String)
47
     */
48
    @Override
49
    public Logger getLogger(String name) {
50
        Logger slf4jLogger = null;
51
        if(name == null) {
52
            name = Logger.ROOT_LOGGER_NAME;
53
        }
54
        // protect against concurrent access of loggerMap
55
        synchronized (this) {
56
            slf4jLogger = loggerMap.get(name);
57
            if (slf4jLogger == null) {
58
                org.apache.log.Logger logkitLogger;
59
                if (name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME)) {
60
                    logkitLogger = Hierarchy.getDefaultHierarchy().getRootLogger();
61
                } else {
62
                    logkitLogger = LoggingManager.getLoggerFor(name);
63
                }
64
                slf4jLogger = new LogkitLoggerAdapter(logkitLogger);
65
                loggerMap.put(name, slf4jLogger);
66
            }
67
        }
68
        return slf4jLogger;
69
    }
70
}
(-)a/src/core/org/slf4j/impl/StaticLoggerBinder.java (-79 lines)
Lines 1-78 Link Here
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
19
package org.slf4j.impl;
20
21
import org.apache.jmeter.logging.LogkitLoggerFactory;
22
import org.slf4j.ILoggerFactory;
23
import org.slf4j.LoggerFactory;
24
import org.slf4j.spi.LoggerFactoryBinder;
25
26
/**
27
 * The binding of {@link LoggerFactory} class with an actual instance of
28
 * {@link ILoggerFactory} is performed using information returned by this class.
29
 * 
30
 * @since 3.0
31
 */
32
public class StaticLoggerBinder implements LoggerFactoryBinder {
33
34
    /**
35
     * The unique instance of this class.
36
     * 
37
     */
38
    private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
39
40
    /**
41
     * Return the singleton of this class.
42
     * 
43
     * @return the StaticLoggerBinder singleton
44
     */
45
    public static final StaticLoggerBinder getSingleton() {
46
        return SINGLETON;
47
    }
48
49
    /**
50
     * Declare the version of the SLF4J API this implementation is compiled
51
     * against. The value of this field is usually modified with each release.
52
     */
53
    // to avoid constant folding by the compiler, this field must *not* be final
54
    public static String REQUESTED_API_VERSION = "1.7"; // !final
55
56
    private static final String loggerFactoryClassStr = LogkitLoggerFactory.class
57
            .getName();
58
59
    /**
60
     * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
61
     * method should always be the same object
62
     */
63
    private final ILoggerFactory loggerFactory;
64
65
    private StaticLoggerBinder() {
66
        loggerFactory = new LogkitLoggerFactory();
67
    }
68
69
    @Override
70
    public ILoggerFactory getLoggerFactory() {
71
        return loggerFactory;
72
    }
73
74
    @Override
75
    public String getLoggerFactoryClassStr() {
76
        return loggerFactoryClassStr;
77
    }
78
}
79
- 

Return to bug 59777