X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=listener%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Flistener%2FLoggingEventListener.java;fp=listener%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Flistener%2FLoggingEventListener.java;h=f623b135bb28787abf865bbc8f3c3278a5f2c868;hb=fdc1e06b2b99816e68d8fe3e8a8f823d38ee31e6;hp=0000000000000000000000000000000000000000;hpb=a16d490b5c490e87e481c1dee0c95d4b6b3ee904;p=xmlrouter diff --git a/listener/src/main/java/org/wamblee/xmlrouter/listener/LoggingEventListener.java b/listener/src/main/java/org/wamblee/xmlrouter/listener/LoggingEventListener.java new file mode 100644 index 0000000..f623b13 --- /dev/null +++ b/listener/src/main/java/org/wamblee/xmlrouter/listener/LoggingEventListener.java @@ -0,0 +1,81 @@ +/* + * Copyright 2005-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.xmlrouter.listener; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.print.attribute.standard.Destination; +import javax.xml.transform.dom.DOMSource; + +import org.wamblee.xml.XMLDocument; +import org.wamblee.xmlrouter.common.Id; +import org.wamblee.xmlrouter.config.Transformation; + +/** + * Event logger that simply logs to java.util logging. + * + * @author Erik Brakkee + * + */ +public class LoggingEventListener implements EventListener { + private static final Logger LOGGER = Logger + .getLogger(LoggingEventListener.class.getName()); + + private Level level; + + public LoggingEventListener(Level aLevel) { + level = aLevel; + } + + @Override + public void delivered(String aDocType, Id aEventId, + DOMSource aEvent, List aSequence, + Id aDestination, String aDestinationName, + boolean aSuccessFlag) { + if (LOGGER.isLoggable(level)) { + LOGGER.log(level, "event delivered: document type '" + aDocType + + "', eventId " + aEventId + ", event '" + + new XMLDocument(aEvent).print(true) + "', sequence '" + + getSequenceString(aSequence) + "', destionationId " + + aDestination + ", destinationName '" + aDestinationName + "'"); + } + } + + private String getSequenceString(List aSequence) { + StringBuffer buf = new StringBuffer(); + for (Transformation transformation : aSequence) { + buf.append(transformation.getName()); + buf.append("("); + buf.append(transformation.getFromType()); + buf.append("->"); + buf.append(transformation.getToType()); + buf.append(")"); + } + return buf.toString(); + } + + @Override + public void notDelivered(String aDocumentType, Id aEventId, + DOMSource aEvent) { + if (LOGGER.isLoggable(level)) { + LOGGER.log(level, "event not delivered: document type '" + + aDocumentType + "', eventId " + aEventId + ", event '" + + new XMLDocument(aEvent).print(true) + "'"); + } + } +}