This class provides a concrete implementation of the Observer protocol. The publish method of this class outputs the log records that it receives to a FILE * supplied at construction and then flushes the stream.

Synopsis

Declared in <ball_cstdioobserver.h>

class CstdioObserver
    : public Observer

Base Classes

Name

Description

Observer

This class provides a protocol for receiving and processing log record output.

Type Aliases

Name

Description

RecordFormatter

LogRecordFunctor is an alias for the type of the functor used for formatting log records to a stream.

allocator_type

allocator_type is an alias for the type of allocator used by this class.

Member Functions

Name

Description

CstdioObserver [constructor]

Create a cstdio observer that transmits log records to the specified stream. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used. Note that a default record format is in effect for cstdio logging (see setFormat).

~CstdioObserver [destructor] [virtual]

Destroy this cstdio observer.

disablePublishInLocalTime

Disable publishing of the timestamp attribute of records in local time by this cstdio observer; henceforth, timestamps will be in UTC time. This method has no effect if publishing in local time is not enabled.

enablePublishInLocalTime

Enable publishing of the timestamp attribute of records in local time by this cstdio observer. By default, timestamps are published in UTC time. Note that this method also affects timestamps for formatters that use them.

getFormat

Return the format config of the last successful setFormat call.

isPublishInLocalTimeEnabled

Return true if this observer writes the timestamp attribute of records that it publishes in local time by default, and false otherwise (in which case timestamps are written by default in UTC time).

publish

publish overloads

releaseRecords [virtual]

Discard any shared reference to a Record object that was supplied to the publish method, and is held by this observer. Note that this operation should be called if resources underlying the previously provided shared‐pointers must be released. This method intentionally does nothing as no such resources are held; we publish all records immediately.

setFormat

Set the formatting functor used when writing records to the log of this cstdio observer to a functor created according to the specified, possibly URI‐like, scheme‐tagged format. Return zero if the setup with the specified arguments was successful and also save the format to be later retrievable using getFormat. Otherwise (if no matching scheme could be found or the configuration is invalid) return a non‐zero value and do not change the log record formatter used by this object. Note that a default format ("n%d %p %t %s %f %l %c %m %un") is in effect until this method or setFormatFunctor is called. Also, notice that the observer emits newline characters at the beginning and at the end of a log record by (the) default (format), so the user needs to add them explicitly to (text) format strings to preserve that behavior.

setFormatFunctor

Set the formatting functor used when writing records to the log of this cstdio observer to the specified formatter functor. Note that a default format ("n%d %p %t %s %f %l %c %m %un") is in effect until this method or setFormat is called (see ball_recordstringformatter). Also note that the observer emits newline characters at the beginning and at the end of a log record by default, so the user needs to add them explicitly to the format string to preserve this behavior. Note that this method is not able to communicate the timezone default settings to the formatter, prefer setFormat.

operator BloombergLP::bslmf::NestedTraitDeclaration<CstdioObserver, UsesBslmaAllocator>

Declare that this type uses a bslma allocator.

Using Declarations

Name

Description

publish

Import the base‐class publish overloads.

Created with MrDocs