Error using OtrosLogViewer with SocketHubAppender

113 views Asked by At

I'm trying to use something besides Chainsaw, which seems to not be supported any more and cannot be started with Java 1.8.0_72. I was trying OtrosLogView using the same Log4j file that I used with Chainsaw, but I keep getting this error:

java.lang.ClassCastException: java.net.Inet4Address cannot be cast to java.lang.String
        at pl.otros.logview.parser.log4j.Log4jUtil.translateLog4j(Log4jUtil.java:68)
        at pl.otros.logview.importer.Log4jSerilizedLogImporter.importLogs(Log4jSerilizedLogImporter.java:67)
        at pl.otros.logview.reader.SocketLogReader$SocketHandler.run(SocketLogReader.java:103)
        at java.lang.Thread.run(Thread.java:745)

Here are the details of my log4j configuration file:

log4j.rootCategory=DEBUG stdout, SOCKET

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] [%t] %-5p %c{1}:%L - %m%n
log4j.appender.stdout.threshold=ERROR

log4j.appender.SOCKET=org.apache.log4j.net.SocketHubAppender
log4j.appender.SOCKET.RemoteHost=localhost
log4j.appender.SOCKET.Port=50505
log4j.appender.SOCKET.LocationInfo=true
log4j.appender.SOCKET.ReconnectionDelay=10000
log4j.appender.SOCKET.threshold=DEBUG

I'm really frustrated that it won't work. I took a look at the source code of the OtrosLogViewer and I can see where the error occurs here:

// Starting from line 64 of pl.otros.logview.parser.log4j.Log4jUtil.translateLog4j() 
ld.setProperties(IMMUTABLE_EMPTY_MAP);
Map properties = event.getProperties();
if (properties != null) {
      Map<String, String> props = new HashMap<>(properties.size());
      for (Object key : properties.keySet()) {
        String value = (String) properties.get(key);
        if (StringUtils.isNotBlank(value)) {
          props.put(key.toString(), value);
        }
      }
      if (props.size() > 0) {
        ld.setProperties(props);
      }
}

As you can see it treats all properties as if they are String's, but as the error reports not all properties are string since one of them is an Inet4Address. Why didn't they just do a toString on the value instead of casting it? I guess I can check out the code and try to fix it myself, but is there a way to get the SocketHubAdapter to send the property values as strings?

0

There are 0 answers