Implementing logging from external library

Hi Folks,

I am trying to pull in the DNP3 library from here: Logging | DNP3 1.4.1.

I have successfully implemented the bundle wrapper to pull in the maven library into Openems. Please keep in mind my Java is fairly limited, but essentially I am struggling with pulling in the ConsoleLogger and linking it with the openems console. So that I can see the logs of the lib in the openems console.

This is how the lib suggest you need to configure the logging callback:

class ConsoleLogger implements Logger {

  @Override
  public void onMessage(LogLevel level, String message) {
    System.out.print(message);
  }
}

Logging.configure(new LoggingConfig(), new ConsoleLogger());

Any ideas of how best to implement this?

Kind regards,

Bart

Hi Guys,

So stupid me, seems like the below does the trick:

import org.slf4j.LoggerFactory;


//callback interface used to receive log messages
class TestLogger implements Logger {
	
 private final org.slf4j.Logger log = LoggerFactory.getLogger(TestLogger.class);

  	@Override
	  public void onMessage(LogLevel level, String message) {
	    //System.out.print(message);
		// Map DNP3 log levels to SLF4J log levels as needed
		  switch (level) {
		      case TRACE:
		    	  log.trace(message);
		          break;
		      case DEBUG:
		    	  log.debug(message);
		          break;
		      case INFO:
		    	  log.info(message);
		          break;
		      case WARN:
		    	  log.warn(message);
		          break;
		      case ERROR:
		    	  log.error(message);
		          break;
		  }
	}
}

Cheers

2 Likes