I am trying to get an logger and add a specific appender to it. My code is very simple but I am not sure how to get this working.
val loggerInstance = LoggerFactory.getLogger("FOO.class")
var fileAppender = new FileAppender()
// fileAppender .setFile , sietPattern etc..the parameters i want
loggerInstance.addAppender(fileAppender)
I get an error here
Multiple markers at this line
- type mismatch; found : ch.qos.logback.core.FileAppender[Nothing] required:
ch.qos.logback.core.Appender[ch.qos.logback.classic.spi.ILoggingEvent] Note: Nothing <:
ch.qos.logback.classic.spi.ILoggingEvent, but Java-defined trait Appender is invariant in type E. You may wish to investigate a
wildcard type such as `_ <: ch.qos.logback.classic.spi.ILoggingEvent`. (SLS 3.2.10)
- Line breakpoint:loggerchange [line: 76] - addAppender
I have no clue what this error means and how to solve it. Can someone help me?
EDIT :
I tried to do what was told by drexin. I was not able to extend the interface and define the functions . There were only three functions , setName,getName, and doAppend. i am not sure as how to define these functions. Meanwhile i tried something and removed the errors. Please look into the code and let me know if what i am doing makes any sense .
val encoder = new PatternLayoutEncoder()
encoder2.setContext(context)
encoder2.setPattern("%msg%")
fileAppender.setAppend(true)
fileAppender.setContext(context)
fileAppender.setEncoder(encoder2.asInstanceOf[Encoder[Nothing]])
loggerInstance.asInstanceOf[Logger].addAppender(fileAppender
.asInstanceOf[Appender[ILoggingEvent]])
I know using asInstanceOf is not a smart way of coding but for now i want to make this work . When i execute this code i am getting the file in which i want to log but there is no logs inside it. I have checked for level errors , but that's not the case. i believe there is something wrong with encoder/layout. I am not sure how to fix it. Can someone show me how to either extend the class and apply the functions or what is wrong in this new code .