I am new to this fancy language scala and I am trying to create a library for logging scala actors. My library has a class Logger which extends the Actor class. So any Scala application which uses actor model can extend from this class instead or the Actor class for added logging functionality. Eg. class MyClass extends Logger. In my Logger class I have implemented the logic that whenever someone sends a message to some actor it is logged by the log file of the sending actor. For this, whenever someone sends a message to another actor instead of calling the scala send function, like
caller ! msg
the user of the library calls
send(caller,msg)
The library function will then create an entry for this message in the log. This works fine. I wish to add similar functionality for messages received by an actor. That is, whenever an actor receives a message the library should make an entry for the received message in the log file. One way of doing this is that whenever the user receives a method he can explicitly call a log method like this,
while (true) {
receive {
case msg =>
log(sender, msg)
// do some stuff
}
}
The log function makes an entry in the log. I want that the user should not need to write this line log(sender, msg) so that the library is transparent to the user and there is no added code which the user needs to write and everything is implicitly logged by the Logger class. Is there a way to achieve this? Thanks in advance.