Reputation: 1435
I am trying to write an appender for logback that sends all logging events to an akka actor which maintains a list of remote actors that monitor the system.
The appender seemed relatively easy at first:
class MonitoringAppender extends AppenderBase[ILoggingEvent] {
def mon = Main.system.actorSelection("akka://Backend/user/MonitorEndpoint")
override def append(event: ILoggingEvent): Unit = {
mon ! Log(event.toString)
}
}
Main
is the object that starts up the system and therefore has a reference to the ActorSystem
. The problem I have is that Main
doesn't seem to be loaded when the first log messages come in and the whole application crashes.
I tried to delay the usage of Main
as far as possible by making mon
a def
.
Is there the possibility, that Main
can add this appender after the application has started or have this appender deactivated and activate it once the system is ready to avoid this issue?
Upvotes: 1
Views: 384
Reputation: 35443
I think a better option here is to listen to the logging event stream as long as you are using Akka's logging facility. If you read the docs here, specifically the section on Loggers, it should give you a good idea of how to add your custom logging handler into the logging config.
Upvotes: 3