folly::AsyncLogWriter

An abstract LogWriter implementation that provides functionality for asynchronous IO operations. Users can subclass this class and provide their own IO operation implementation by overriding performIO method. This class will automatically manage incoming log messages and call the method in appropriate time.

Synopsis

Declared in <folly/logging/AsyncLogWriter.h>

class AsyncLogWriter
    : public LogWriter

Description

This class performs the log I/O in a separarate thread.

The advantage of this class over ImmediateFileWriter is that logging I/O can never slow down or block your normal program operation. If log messages are generated faster than they can be written, messages will be dropped (and an indication of how many messages were dropped will be written to the log file when we are able to catch up a bit.)

However, one downside is that if your program crashes, not all log messages may have been written, so you may lose messages generated immediately before the crash.

Base Classes

NameDescription
LogWriterWrites serialized log messages to an output.

Type Aliases

NameDescription
DiscardCallback Callback type invoked with the number of discarded messages.

Enums

NameDescription
Flags Bit flag values for use with writeMessage()

Member Functions

NameDescription
AsyncLogWriter [constructor]Constructs the writer and starts its I/O thread.
~AsyncLogWriter [destructor] [virtual]Stops the I/O thread and destroys the writer.
flush [virtual]Block until the I/O thread has finished writing all messages that were already enqueued when flush() was called.
getMaxBufferSize Get the maximum buffer size for this AsyncLogWriter, in bytes.
setMaxBufferSize Set the maximum buffer size for this AsyncLogWriter, in bytes.
ttyOutput [virtual]Is the log writer writing to a tty or not.
writeMessage Enqueues a serialized message for asynchronous writing.
writeMessageSync [virtual]Write a message synchronously.

Static Member Functions

NameDescription
setDiscardCallback Set a callback to be invoked when log messages have been discarded.

Static Data Members

NameDescription
kDefaultMaxBufferSize The default maximum buffer size.

Protected Member Functions

NameDescription
cleanup Drain up the log message queue. Subclasses must call this method in their destructors to avoid losing log messages at shutdown.

Derived Classes

NameDescription
AsyncFileWriter An implementation of folly::AsyncLogWriter that writes log messages into a file.