https://issues.apache.org/bugzilla/show_bug.cgi?id=50238
Summary: wrong log levels logged with the serialized
LoggingEvent
Product: Log4j
Version: 1.2
Platform: All
OS/Version: All
Status: NEW
Severity: critical
Priority: P2
Component: Appender
AssignedTo: [email protected]
ReportedBy: [email protected]
This occurs under logging with serialized LoggerEvent as
SimpleSocketServe does.
For example
Multi processed socket clients send logs to SocketServer, and server
reads serialized LoggingEvents with o.a.l.s.LoggingEvent#readObject(),
this calls internally o.a.l.s.LoggingEvent#readLevel(ObjectInputStream)
which uses thead-unsafe `static final` variable. (see below at line 439)
This results in inconsistent log levels.
I reproduced with 4-processes socket clients, each client has 10-threads,
toward single-process SimpleSocketServer. Clients sent 80,000 logs in
all, and about 10 of them were wrong leveled.
[LoggingEvent.java]
142: static final Integer[] PARAM_ARRAY = new Integer[1];
...
417: private
418: void readLevel(ObjectInputStream ois)
419: throws java.io.IOException, ClassNotFoundException {
420:
421: int p = ois.readInt();
422: try {
423: String className = (String) ois.readObject();
424: if(className == null) {
425: level = Level.toLevel(p);
426: } else {
427: Method m = (Method) methodCache.get(className);
428: if(m == null) {
429: Class clazz = Loader.loadClass(className);
430: // Note that we use Class.getDeclaredMethod instead of
431: // Class.getMethod. This assumes that the Level subclass
432: // implements the toLevel(int) method which is a
433: // requirement. Actually, it does not make sense for Level
434: // subclasses NOT to implement this method. Also note that
435: // only Level can be subclassed and not Priority.
436: m = clazz.getDeclaredMethod(TO_LEVEL, TO_LEVEL_PARAMS);
437: methodCache.put(className, m);
438: }
439: PARAM_ARRAY[0] = new Integer(p); // <=== !!! thread-unsafe !!!
440: level = (Level) m.invoke(null, PARAM_ARRAY);
441: }
442: } catch(InvocationTargetException e) {
443: if (e.getTargetException() instanceof InterruptedException
444: || e.getTargetException() instanceof
InterruptedIOException) {
445: Thread.currentThread().interrupt();
446: }
447: LogLog.warn("Level deserialization failed, reverting to default.", e);
448: level = Level.toLevel(p);
449: } catch(NoSuchMethodException e) {
450: LogLog.warn("Level deserialization failed, reverting to default.",
e);
451: level = Level.toLevel(p);
452: } catch(IllegalAccessException e) {
453: LogLog.warn("Level deserialization failed, reverting to default.",
e);
454: level = Level.toLevel(p);
455: } catch(RuntimeException e) {
456: LogLog.warn("Level deserialization failed, reverting to default.",
e);
457: level = Level.toLevel(p);
458: }
459: }
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]