BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball::CstdioObserver Class Reference

#include <ball_cstdioobserver.h>

Inheritance diagram for ball::CstdioObserver:
ball::Observer

Detailed Description

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.

See ball_cstdioobserver

Public Types

typedef RecordFormatterFunctor::Type RecordFormatter
 
typedef bsl::allocator< char > allocator_type
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (CstdioObserver, bslma::UsesBslmaAllocator)
 
 CstdioObserver (FILE *stream, const allocator_type &allocator=allocator_type())
 
 ~CstdioObserver () BSLS_KEYWORD_OVERRIDE
 
void publish (const bsl::shared_ptr< const Record > &record, const Context &context) BSLS_KEYWORD_OVERRIDE
 
void releaseRecords () BSLS_KEYWORD_OVERRIDE
 
void disablePublishInLocalTime ()
 
void enablePublishInLocalTime ()
 
void setFormatFunctor (const RecordFormatter &formatter)
 
int setFormat (const bsl::string_view &format)
 
bool isPublishInLocalTimeEnabled () const
 
const bsl::stringgetFormat () const
 
virtual void publish (const Record &record, const Context &context)
 
virtual void publish (const bsl::shared_ptr< const Record > &record, const Context &context)
 
- Public Member Functions inherited from ball::Observer
virtual ~Observer ()
 

Member Typedef Documentation

◆ allocator_type

◆ RecordFormatter

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

Constructor & Destructor Documentation

◆ CstdioObserver()

ball::CstdioObserver::CstdioObserver ( FILE *  stream,
const allocator_type allocator = allocator_type() 
)
explicit

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
Note that a default record format is in effect for cstdio logging (see setFormat).

◆ ~CstdioObserver()

ball::CstdioObserver::~CstdioObserver ( )

Destroy this cstdio observer.

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

ball::CstdioObserver::BSLMF_NESTED_TRAIT_DECLARATION ( CstdioObserver  ,
bslma::UsesBslmaAllocator   
)

◆ disablePublishInLocalTime()

void ball::CstdioObserver::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()

void ball::CstdioObserver::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
Note that this method also affects timestamps for formatters that use them.

◆ getFormat()

const bsl::string & ball::CstdioObserver::getFormat ( ) const

Return the format config of the last successful setFormat call.

◆ isPublishInLocalTimeEnabled()

bool ball::CstdioObserver::isPublishInLocalTimeEnabled ( ) const

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() [1/3]

virtual void ball::Observer::publish ( const bsl::shared_ptr< const Record > &  record,
const Context context 
)
virtual

Process the specified log record having the specified publishing context. The exact definition of publish depends on the implementing class, though the intention is that the log record (whose publication has occurred according to context) be distributed in a human or machine readable form.

Reimplemented from ball::Observer.

◆ publish() [2/3]

void ball::CstdioObserver::publish ( const bsl::shared_ptr< const Record > &  record,
const Context context 
)
virtual

Process the specified log record having the specified publishing context. Print record and context to the FILE * supplied at construction.

Precondition
The behavior is undefined if record or context is modified during the execution of this method.

Reimplemented from ball::Observer.

◆ publish() [3/3]

virtual void ball::Observer::publish ( const Record record,
const Context context 
)
virtual

Process the specified log record having the specified publishing context.

Deprecated:
Use the alternative publish overload instead.

Reimplemented from ball::Observer.

◆ releaseRecords()

void ball::CstdioObserver::releaseRecords ( )
inlinevirtual

Discard any shared reference to a Record object that was supplied to the publish method, and is held by this observer.

Note
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.

Reimplemented from ball::Observer.

◆ setFormat()

int ball::CstdioObserver::setFormat ( const bsl::string_view format)

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
Note that a default format ("\n%d %p %t %s %f %l %c %m %u\n") 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()

void ball::CstdioObserver::setFormatFunctor ( const RecordFormatter formatter)

Set the formatting functor used when writing records to the log of this cstdio observer to the specified formatter functor.

Note
Note that a default format ("\n%d %p %t %s %f %l %c %m %u\n") 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.

The documentation for this class was generated from the following file: