我试图编写一个JMX bean,它可以改变所有akka actor的当前日志记录级别,如下所示:
@ManagedResource(objectName = "com.company:name=LoggingLevelHandler")
public class LoggingLevelHandlerJmxBean {
@Autowired
private ActorSystem system;
@ManagedOperation(description = "Change logging level of the application")
public boolean changeLogLevel(String newLevel) {
EventStream currentStream = system.eventStream();
currentStream.setLogLevel(Logging.levelFor(newLevel).get());
return true;
}
private akka.event.Logging.LogLevel getLevelForName(String name){
switch(name) {
case("ERROR"):{
return Logging.ErrorLevel();
}
case("WARN"):{
return Logging.WarningLevel();
}
case("INFO"):{
return Logging.InfoLevel();
}
case("DEBUG"):{
return Logging.DebugLevel();
}
}
return akka.event.Logging.InfoLevel();
}
}
我在字符串中收到错误Error:(31, 69) java: incompatible types: akka.event.Logging.LogLevel cannot be converted to int
:
currentStream.setLogLevel(Logging.levelFor(newLevel).get());
当我将其更改为currentStream.setLogLevel(Logging.InfoLevel())
时,此错误消失。但是当我尝试使用自定义函数getLevelForName(仅用于实验)时,它又出现了。 currentStream.setLogLevel(Logging.levelFor("error").get())
会导致相同的编译错误。好像任何额外的返回(或VM堆栈顶部的返回地址?)都会导致错误。
Javac:1.8.0_91
akka:2.4.4
构建系统:maven 3.3.9
感谢您的帮助
干杯,阿列克谢