BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball::StreamObserver Class Reference

#include <ball_streamobserver.h>

Inheritance diagram for ball::StreamObserver:
ball::Observer

Public Types

typedef bsl::function< void(bsl::ostream &, const Record &)> RecordFormatFunctor
 
typedef bsl::allocator< char > allocator_type
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (StreamObserver, bslma::UsesBslmaAllocator)
 
 StreamObserver (bsl::ostream *stream, const allocator_type &allocator=allocator_type())
 
 ~StreamObserver () BSLS_KEYWORD_OVERRIDE
 Destroy this stream observer.
 
void publish (const bsl::shared_ptr< const Record > &record, const Context &context) BSLS_KEYWORD_OVERRIDE
 
void releaseRecords () BSLS_KEYWORD_OVERRIDE
 
void setRecordFormatFunctor (const RecordFormatFunctor &formatter)
 
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 ()
 Destroy this 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 an instance of bsl::ostream supplied at construction.

See ball_streamobserver

Member Typedef Documentation

◆ allocator_type

◆ RecordFormatFunctor

typedef bsl::function<void(bsl::ostream&, const Record&)> ball::StreamObserver::RecordFormatFunctor

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

Constructor & Destructor Documentation

◆ StreamObserver()

ball::StreamObserver::StreamObserver ( bsl::ostream *  stream,
const allocator_type allocator = allocator_type() 
)
explicit

Create a stream 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 stream logging (see setLogFileFunctor).

◆ ~StreamObserver()

ball::StreamObserver::~StreamObserver ( )

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

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

◆ 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::StreamObserver::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 bsl::ostream supplied at construction. 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::StreamObserver::releaseRecords ( )
inlinevirtual

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.

Reimplemented from ball::Observer.

◆ setRecordFormatFunctor()

void ball::StreamObserver::setRecordFormatFunctor ( const RecordFormatFunctor formatter)

Set the formatting functor used when writing records to the log file of this file observer to the specified formatter functor. Note that a default format ("\n%d %p %t %s %f %l %c %m %u\n") is in effect until this method 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.


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