Hi all,
I've created the log appender that write a log out through the
XMPPService for sl4j and logback.
XmppAppender.java
---
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.*;
import com.google.appengine.api.xmpp.*;
public class XmppAppender extends AppenderBase<ILoggingEvent> {
private XMPPService service = XMPPServiceFactory.getXMPPService();
private String notifyTo;
public String getNotifyTo() {
return notifyTo;
}
public void setNotifyTo(String notifyTo) {
if (notifyTo == null || notifyTo.isEmpty()) {
throw new IllegalArgumentException();
}
this.notifyTo = notifyTo;
}
@Override
protected void append(ILoggingEvent eventObject) {
JID jid = new JID(notifyTo);
Message message = new MessageBuilder()
.withMessageType(MessageType.CHAT)
.withRecipientJids(jid)
.withBody(getLayout().doLayout(eventObject))
.build();
switch (service.sendMessage(message).getStatusMap().get(jid)) {
case SUCCESS:
return;
case INVALID_ID:
throw new LogbackException("failed to append log event for
invalid id:" + jid);
case OTHER_ERROR:
throw new LogbackException("failed to append log event for
unknown error:" + jid);
default:
throw new AssertionError();
}
}
}
---
sample logback.xml as following:
logback.xml
---
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="XMPP"
class="com.gluegent.tools.appengine.logging.XmppAppender">
<notifyTo>developper-account*at*gmail.com</notifyTo>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%-5p %d [%t] %m%n</pattern>
</layout>
</appender>
<root>
<level value="TRACE" />
<appender-ref ref="XMPP" />
</root>
</configuration>
---
Then, invite <AppId>*at*appspot.com to the desired GTalk account.
That's it!! Enjoy your Log Life!!
Since XMPPService works for the deault version only, you can not use
this appender for the others.
--
cynipe
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.