Temporarily capture a file descriptor by redirecting it into a file. You can consume its entire output thus far via read(), incrementally via readIncremental(), or via callback using chunk_cob. Great for testing logging (see also glog*Pattern()).

Synopsis

Declared in <folly/testing/TestUtil.h>

class CaptureFD;

Type Aliases

Name

Description

ChunkCob

Callback type invoked with each captured chunk of output.

Member Functions

Name

Description

CaptureFD [constructor]

Begins capturing the given file descriptor by redirecting it into a file.

~CaptureFD [destructor]

Stops capturing and restores the file descriptor.

read

Reads the whole file into a string, but does not remove the redirect.

readIncremental

Read any bytes that were appended to the file since the last readIncremental. Great for testing line‐by‐line output.

release

Restore the captured FD to its original state. It can be useful to do this before the destructor so that you can read() the captured data and log about it to the formerly captured stderr or stdout.

Created with MrDocs