mirror of https://github.com/apache/activemq.git
Improve how trace logging is handled in the AMQP transport.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1495057 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
661801ebcd
commit
e8eb58ada3
|
@ -102,7 +102,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class AmqpProtocolConverter {
|
||||
|
||||
static final Logger TRACE_FRAMES = AmqpTransportFilter.TRACE_FRAMES;
|
||||
public static final EnumSet<EndpointState> UNINITIALIZED_SET = EnumSet.of(EndpointState.UNINITIALIZED);
|
||||
public static final EnumSet<EndpointState> INITIALIZED_SET = EnumSet.complementOf(UNINITIALIZED_SET);
|
||||
public static final EnumSet<EndpointState> ACTIVE_STATE = EnumSet.of(EndpointState.ACTIVE);
|
||||
|
@ -126,27 +126,32 @@ class AmqpProtocolConverter {
|
|||
public AmqpProtocolConverter(AmqpTransport transport, BrokerContext brokerContext) {
|
||||
this.amqpTransport = transport;
|
||||
this.protonTransport.bind(this.protonConnection);
|
||||
if (transport.isTrace()) {
|
||||
updateTracer();
|
||||
}
|
||||
|
||||
void updateTracer() {
|
||||
if (amqpTransport.isTrace()) {
|
||||
this.protonTransport.setProtocolTracer(new ProtocolTracer() {
|
||||
@Override
|
||||
public void receivedFrame(TransportFrame transportFrame) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("%s | RECV: %s",
|
||||
amqpTransport.getRemoteAddress(), transportFrame.getBody()));
|
||||
if (TRACE_FRAMES.isTraceEnabled()) {
|
||||
TRACE_FRAMES.trace(String.format("%s | RECV: %s",
|
||||
AmqpProtocolConverter.this.amqpTransport.getRemoteAddress(), transportFrame.getBody()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sentFrame(TransportFrame transportFrame) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("%s | SENT: %s",
|
||||
amqpTransport.getRemoteAddress(), transportFrame.getBody()));
|
||||
if (TRACE_FRAMES.isTraceEnabled()) {
|
||||
TRACE_FRAMES.trace(String.format("%s | SENT: %s",
|
||||
AmqpProtocolConverter.this.amqpTransport.getRemoteAddress(), transportFrame.getBody()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void pumpProtonToSocket() {
|
||||
try {
|
||||
int size = 1024 * 64;
|
||||
|
|
|
@ -39,7 +39,8 @@ import java.security.cert.X509Certificate;
|
|||
*/
|
||||
public class AmqpTransportFilter extends TransportFilter implements AmqpTransport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AmqpTransportFilter.class);
|
||||
private static final Logger TRACE = LoggerFactory.getLogger(AmqpTransportFilter.class.getPackage().getName() + ".AMQPIO");
|
||||
static final Logger TRACE_BYTES = LoggerFactory.getLogger(AmqpTransportFilter.class.getPackage().getName() + ".BYTES");
|
||||
static final Logger TRACE_FRAMES = LoggerFactory.getLogger(AmqpTransportFilter.class.getPackage().getName() + ".FRAMES");
|
||||
private final AmqpProtocolConverter protocolConverter;
|
||||
// private AmqpInactivityMonitor monitor;
|
||||
private AmqpWireFormat wireFormat;
|
||||
|
@ -86,8 +87,8 @@ public class AmqpTransportFilter extends TransportFilter implements AmqpTranspor
|
|||
|
||||
public void onCommand(Object command) {
|
||||
try {
|
||||
if (trace) {
|
||||
TRACE.trace("Received: \n" + command);
|
||||
if (trace && TRACE_BYTES.isTraceEnabled()) {
|
||||
TRACE_BYTES.trace("Received: \n" + command);
|
||||
}
|
||||
protocolConverter.lock.lock();
|
||||
try {
|
||||
|
@ -112,8 +113,8 @@ public class AmqpTransportFilter extends TransportFilter implements AmqpTranspor
|
|||
|
||||
public void sendToAmqp(Object command) throws IOException {
|
||||
assert protocolConverter.lock.isHeldByCurrentThread();
|
||||
if (trace) {
|
||||
TRACE.trace("Sending: \n" + command);
|
||||
if (trace && TRACE_BYTES.isTraceEnabled()) {
|
||||
TRACE_BYTES.trace("Sending: \n" + command);
|
||||
}
|
||||
Transport n = next;
|
||||
if (n != null) {
|
||||
|
@ -138,6 +139,7 @@ public class AmqpTransportFilter extends TransportFilter implements AmqpTranspor
|
|||
|
||||
public void setTrace(boolean trace) {
|
||||
this.trace = trace;
|
||||
this.protocolConverter.updateTracer();
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
|
|
@ -56,29 +56,33 @@ public class ActiveMQAdmin implements Admin {
|
|||
}
|
||||
}
|
||||
|
||||
static public void enableJMSFrameTracing() throws FileNotFoundException {
|
||||
final SimpleFormatter formatter = new SimpleFormatter();
|
||||
String outputStreamName = System.getProperty("java.io.tmpdir") + "/amqp-trace.txt";
|
||||
final PrintStream out = new PrintStream(new FileOutputStream(new File(outputStreamName)));
|
||||
Handler handler = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord r) {
|
||||
out.println(String.format("%s:%s", r.getLoggerName(), r.getMessage()));
|
||||
}
|
||||
static public void enableJMSFrameTracing() {
|
||||
try {
|
||||
final SimpleFormatter formatter = new SimpleFormatter();
|
||||
String outputStreamName = "amqp-trace.txt";
|
||||
final PrintStream out = new PrintStream(new FileOutputStream(new File(outputStreamName)));
|
||||
Handler handler = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord r) {
|
||||
out.println(String.format("%s:%s", r.getLoggerName(), r.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
out.flush();
|
||||
}
|
||||
@Override
|
||||
public void flush() {
|
||||
out.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
}
|
||||
};
|
||||
|
||||
Logger log = Logger.getLogger("FRM");
|
||||
log.addHandler(handler);
|
||||
log.setLevel(Level.FINEST);
|
||||
Logger log = Logger.getLogger("FRM");
|
||||
log.addHandler(handler);
|
||||
log.setLevel(Level.FINEST);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#
|
||||
log4j.rootLogger=WARN, console, file
|
||||
log4j.logger.org.apache.activemq=INFO
|
||||
log4j.logger.org.apache.activemq.transport.amqp=TRACE
|
||||
log4j.logger.org.apache.activemq.transport.amqp=INFO
|
||||
log4j.logger.org.apache.activemq.transport.amqp.FRAMES=TRACE
|
||||
log4j.logger.org.fusesource=INFO
|
||||
|
||||
# Console will only display warnnings
|
||||
|
|
Loading…
Reference in New Issue