I have a red5 application using java language and I use logback for l开发者_JAVA技巧ogging.
whenever a log is written using logback i want to send it to the message to the user. is there a way to somehow attach to the logger class to be able to do another command when a log is being sent ?
When Logback (but the idea applies to Log4J as well) decides to log given statement (based on logging levels and filters), he sends the ILoggingEvent
to every so called appender attached to a given logger and its parents.
What you want is to implement your own appender (class implementing Appender or preferably extending AppenderBase) and add it to your logback.xml
(simplified):
<root>
<appender class="com.example.YourCustomAppender"/>
</root>
As you can see it is very simple, but before you write your own appender make sure that a similar appender doesn't already exist.
You have to create your custom appender: http://logback.qos.ch/manual/appenders.html
Just implement its doAppend()
as you want. For example send message to user.
If you want to run "another command" you should use similar solution.
精彩评论