Package com.rabbitmq.tools
Class Tracer.AsyncLogger
java.lang.Object
com.rabbitmq.tools.Tracer.AsyncLogger
- All Implemented Interfaces:
Tracer.Logger
- Enclosing class:
Tracer
A
Tracer.Logger designed to print Strings to a designated OutputStream
on a private thread.
Strings are read from a private queue and printed to a buffered PrintStream
which is periodically flushed.
When instantiated the private queue is created (an in-memory ArrayBlockingQueue in this
implementation) and when start()ed the private thread is created and started unless it is
already present. An Tracer.AsyncLogger may be started many times, but only one thread is created.
When stop()ed either the number of starts is decremented, or, if this count reaches zero,
a special element is queued which causes the private thread to end when encountered.
If the private thread is interrupted, the thread will also end, and the count set to zero,
This will cause subsequent stop()s to be ignored, and the next start() will create a new thread.
log(String) never blocks unless the private queue is full; this may never un-block if the Tracer.Logger is stopped.-
Constructor Summary
ConstructorsConstructorDescriptionSame as} with a one-second flush interval.invalid @link
{@link #Tracer.AsyncLogger(OutputStream, int)AsyncLogger(OutputStream os, int flushInterval) Start/stoppable logger that prints to anOutputStreamwith flushes everyflushIntervalmilliseconds. -
Method Summary
Modifier and TypeMethodDescriptionvoidWrite msg to the log.booleanstart()Start logging, that is, printing log entries written usingTracer.Logger.log(String).booleanstop()Stop logging, that is, stop printing log entries written usingTracer.Logger.log(String).
-
Constructor Details
-
AsyncLogger
Same as} with a one-second flush interval.invalid @link
{@link #Tracer.AsyncLogger(OutputStream, int)- Parameters:
os- OutputStream to print to.
-
AsyncLogger
Start/stoppable logger that prints to anOutputStreamwith flushes everyflushIntervalmilliseconds.- Parameters:
os- OutputStream to print to.flushInterval- in milliseconds, time between flushes.
-
-
Method Details
-
log
Description copied from interface:Tracer.LoggerWrite msg to the log. This may block, and may block indefinitely if the logger is stopped.- Specified by:
login interfaceTracer.Logger- Parameters:
message-
-
start
public boolean start()Description copied from interface:Tracer.LoggerStart logging, that is, printing log entries written usingTracer.Logger.log(String). Multiple successive starts are equivalent to a single start.- Specified by:
startin interfaceTracer.Logger- Returns:
trueif start actually started the logger;falseotherwise.
-
stop
public boolean stop()Description copied from interface:Tracer.LoggerStop logging, that is, stop printing log entries written usingTracer.Logger.log(String). Flush preceding writes. The logger can only be stopped if started. Multiple successive stops are equivalent to a single stop.- Specified by:
stopin interfaceTracer.Logger- Returns:
trueif stop actually stopped the logger;falseotherwise.
-