The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::log::Tap Class Reference

Logging Tap. Attach to a TreeNode to intercept logging messages from any NotificationSource nodes in the subtree of that node (including the node itself). More...

#include <Tap.hpp>

Public Member Functions

 Tap (const Tap &)=delete
 Disallow copy construction.
 
Tapoperator= (const Tap &)=delete
 Disallow copy assignment.
 
template<typename DestT >
 Tap (TreeNode *node, const std::string *pcategory, DestT &dest)
 Constructor.
 
template<typename DestT >
 Tap (TreeNode *node, const std::string &category, DestT &dest)
 Constructor.
 
template<typename DestT >
 Tap (const std::string &category, DestT &dest)
 Non-observing Constructor.
 
virtual ~Tap ()
 Destructor.
 
void reset (TreeNode *node)
 Detach the tap from the current node (if any) and re-attach to a new node. Destination and category of observation is maintained.
 
void detach ()
 Detach the tap from a node without destructing. Node can later be reattached to the same or another node using reset. Destination is maintained.
 
const std::string * getCategoryID () const
 
const std::string & getCategoryName () const
 
const DestinationgetDestination () const
 
DestinationgetDestination ()
 
uint64_t getNumMessages () const
 Gets the number of messages seen by this tap having the designated category.
 
TreeNodegetObservedNode () const
 Gets the node at which this tap is observing.
 
bool isObservedNodeExpired () const
 Checks if the node at which this tap is observing has been deleted (i.e. its weak reference has expired)
 

Protected Member Functions

void send_ (const TreeNode &origin, const TreeNode &obs_pt_DO_NOT_USE, const Message &msg)
 Actually send the notification.
 

Detailed Description

Logging Tap. Attach to a TreeNode to intercept logging messages from any NotificationSource nodes in the subtree of that node (including the node itself).

Note
The creation and destruction of Taps is not thread-safe. Construction and destruction must be protected.
noncopyable

Definition at line 27 of file Tap.hpp.

Constructor & Destructor Documentation

◆ Tap() [1/3]

template<typename DestT >
sparta::log::Tap::Tap ( TreeNode node,
const std::string *  pcategory,
DestT &  dest 
)
inline

Constructor.

Template Parameters
DestTDestination type
Parameters
nodeNode that this tap will observe. Must not be nullptr
pcategoryCategory on which this node will filter. Must be interned in StringMananger. If the category string is not already known to be interned, use the alternate constructor for Tap.
destDetination identifier (e.g. std::string filename or ostream&). See sparta::log::Destination and Destination.h for possible types.

Example:

Tap t(root.getChild("a.b.c"), sparta::StringManager::getStringManager().EMPTY, "out.log"); // Opens for write once per session
Tap t(root.getChild("a.b.c"), sparta::log::categories::WARN, std::cerr); // Opens for write once per session
Tap t(root.getChild("a.b.c"), sparta::StringManager::getStringManager().internString("hello"), "out.log"); // Opens for write once per session
static StringManager & getStringManager()
Returns the StringManager singleton.
const std::string *const EMPTY
Holds interned empty strings.
std::string * internString(const std::string &s)
Stores a string in shared space within this manager unless it is already stored.
Logging Tap. Attach to a TreeNode to intercept logging messages from any NotificationSource nodes in ...
Definition Tap.hpp:28
static const std::string *const WARN
Indicates a WARNING.

Definition at line 56 of file Tap.hpp.

Here is the call graph for this function:

◆ Tap() [2/3]

template<typename DestT >
sparta::log::Tap::Tap ( TreeNode node,
const std::string &  category,
DestT &  dest 
)
inline

Constructor.

Example:

Tap t(root.getChild("a.b.c"), "", "out.log"); // Opens for write once per session
Tap t(root.getChild("a.b.c"), "warning", std::cerr); // Opens for write once per session
Tap t(root.getChild("a.b.c"), "hello", "out.log"); // Opens for write once per session

Definition at line 82 of file Tap.hpp.

◆ Tap() [3/3]

template<typename DestT >
sparta::log::Tap::Tap ( const std::string &  category,
DestT &  dest 
)
inline

Non-observing Constructor.

Category and destination must be defined here, but node at which to observe can be specified later via reset.

Example:

Tap t("", "out.log"); // Opens for write once per session
Tap t("warning", std::cerr); // Opens for write once per session
Tap t("hello", "out.log"); // Opens for write once per session
t.reset(root.getChild("a.b.c");

Definition at line 103 of file Tap.hpp.

Here is the call graph for this function:

◆ ~Tap()

virtual sparta::log::Tap::~Tap ( )
inlinevirtual

Destructor.

Note
Does not affect destination

Definition at line 116 of file Tap.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ detach()

void sparta::log::Tap::detach ( )
inline

Detach the tap from a node without destructing. Node can later be reattached to the same or another node using reset. Destination is maintained.

This method exists to stop observing without having to delete any dynamically allocated taps.

Definition at line 150 of file Tap.hpp.

◆ getCategoryID()

const std::string * sparta::log::Tap::getCategoryID ( ) const
inline

Definition at line 173 of file Tap.hpp.

◆ getCategoryName()

const std::string & sparta::log::Tap::getCategoryName ( ) const
inline

Definition at line 177 of file Tap.hpp.

◆ getDestination() [1/2]

Destination * sparta::log::Tap::getDestination ( )
inline

Definition at line 185 of file Tap.hpp.

◆ getDestination() [2/2]

const Destination * sparta::log::Tap::getDestination ( ) const
inline

Definition at line 181 of file Tap.hpp.

◆ getNumMessages()

uint64_t sparta::log::Tap::getNumMessages ( ) const
inline

Gets the number of messages seen by this tap having the designated category.

This is the number of messages forwarded to a destination by this tap.

Definition at line 196 of file Tap.hpp.

◆ getObservedNode()

TreeNode * sparta::log::Tap::getObservedNode ( ) const
inline

Gets the node at which this tap is observing.

Note
This node may have been deleted. To ensure this is safe, use isObservedNodeExpired

Definition at line 205 of file Tap.hpp.

◆ isObservedNodeExpired()

bool sparta::log::Tap::isObservedNodeExpired ( ) const
inline

Checks if the node at which this tap is observing has been deleted (i.e. its weak reference has expired)

Definition at line 213 of file Tap.hpp.

◆ reset()

void sparta::log::Tap::reset ( TreeNode node)
inline

Detach the tap from the current node (if any) and re-attach to a new node. Destination and category of observation is maintained.

Parameters
nodeThe node to attach to. If null, this call effectively behaves like detach.
Note
Destination and category were set in constructor

Definition at line 128 of file Tap.hpp.

Here is the call graph for this function:

◆ send_()

void sparta::log::Tap::send_ ( const TreeNode origin,
const TreeNode obs_pt_DO_NOT_USE,
const Message msg 
)
inlineprotected

Actually send the notification.

Parameters
originNode from which this notification (log message) was generated
obs_pt_DO_NOT_USENode at which this tap was installed causing that node or its ancestors to generate this notification (log message). This node may no longer exist at this time because this tap could outlive the node. So do not access this. This will match the node referenced by node_wptr_, so if it is needed, go through node_wptr_ which knows when the node has expired.
Note
This is a notification callback handler
Warning
Because Taps can exist while a Tree is being destroyed, this function must not access the observation_point argument because it may not exist

Definition at line 234 of file Tap.hpp.

Here is the call graph for this function:

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