OpenMS
Loading...
Searching...
No Matches
LogStreamNotifier Class Reference

Sink-side hook that is notified whenever a LogStream flushes a complete message. More...

#include <OpenMS/CONCEPT/LogStream.h>

Collaboration diagram for LogStreamNotifier:
[legend]

Public Member Functions

 LogStreamNotifier ()
 Construct a detached notifier; registered_at_ starts at nullptr.
 
virtual ~LogStreamNotifier ()
 Destructor; calls unregister so the LogStream stops dispatching to this notifier.
 
virtual void logNotify ()
 Hook called by the registered LogStream after each complete message has been flushed.
 
void registerAt (LogStream &log_stream)
 Attach this notifier to log_stream so its logNotify is invoked after every flushed message.
 
void unregister ()
 Detach from the currently registered LogStream, if any.
 

Protected Attributes

std::stringstream stream_
 Buffer that receives the formatted log line from the registered LogStream; read inside logNotify.
 
LogStreamregistered_at_
 The LogStream this notifier is currently attached to, or nullptr if detached. Managed by registerAt / unregister.
 

Detailed Description

Sink-side hook that is notified whenever a LogStream flushes a complete message.

Subclass this and override logNotify to react to log events programmatically. Register the notifier at a LogStream via registerAt — the log stream then treats the notifier's internal stream_ as one of its output sinks, writes each flushed line into it, and invokes the override at the end of every message. Use stream_ inside logNotify to read the formatted message body.

Lifecycle: unregister is called automatically by the destructor (RAII); calling registerAt while already registered first detaches from the previous stream.

Constructor & Destructor Documentation

◆ LogStreamNotifier()

Construct a detached notifier; registered_at_ starts at nullptr.

◆ ~LogStreamNotifier()

virtual ~LogStreamNotifier ( )
virtual

Destructor; calls unregister so the LogStream stops dispatching to this notifier.

Member Function Documentation

◆ logNotify()

virtual void logNotify ( )
virtual

Hook called by the registered LogStream after each complete message has been flushed.

The default implementation is a no-op. Override in a subclass to react to log events (read stream_ to get the formatted message body).

◆ registerAt()

void registerAt ( LogStream log_stream)

Attach this notifier to log_stream so its logNotify is invoked after every flushed message.

If this notifier is already registered at another stream, the prior registration is released first (via unregister). After the call, the stream_ buffer is added to log_stream's output list and tagged as the notification target.

Parameters
[in,out]log_streamLogStream that will dispatch notifications to this notifier.

◆ unregister()

void unregister ( )

Detach from the currently registered LogStream, if any.

Removes stream_ from the log stream's output list and resets registered_at_ to nullptr. No-op when the notifier is not currently registered.

Member Data Documentation

◆ registered_at_

LogStream* registered_at_
protected

The LogStream this notifier is currently attached to, or nullptr if detached. Managed by registerAt / unregister.

◆ stream_

std::stringstream stream_
protected

Buffer that receives the formatted log line from the registered LogStream; read inside logNotify.