libASPL
Loading...
Searching...
No Matches
aspl::Tracer Class Reference

Operation tracer. More...

#include <aspl/Tracer.hpp>

Classes

struct  Flags
 Operation flags. More...
 
struct  Operation
 Operation info. More...
 

Public Types

enum class  Mode { Noop , Stderr , Syslog , Custom }
 Tracing mode. More...
 
enum class  Style { Hierarchical , Flat }
 Tracing style. More...
 

Public Member Functions

 Tracer (Mode mode=Mode::Syslog, Style style=Style::Hierarchical)
 Initialize tracer. Mode defines where to send messages. Style defines how to format messages.
 
 Tracer (const Tracer &)=delete
 
Traceroperator= (const Tracer &)=delete
 
virtual void OperationBegin (const Operation &operation)
 Called when an operations starts. Default implementation formats arguments and calls Print().
 
virtual void Message (const char *format,...) __attribute__((format(printf
 Called to print message to log. Default implementation formats arguments and calls Print().
 
virtual void virtual void OperationEnd (const Operation &operation, OSStatus status)
 Called when an operations completes. Zero status indicates operation success. Default implementation formats arguments and calls Print().
 

Protected Member Functions

virtual std::string FormatOperationBegin (const Operation &operation, UInt32 depth)
 Format operation begin message into string. Called by default implementation of OperationBegin().
 
virtual std::string FormatMessage (const char *message, UInt32 depth)
 Format message into string. Called by default implementation of Message().
 
virtual std::string FormatOperationEnd (const Operation &operation, OSStatus status, UInt32 depth)
 Format operation end message into string. Called by default implementation of OperationEnd().
 
virtual void Print (const char *message)
 Print message somewhere. Default implementation sends message to syslog if mode is Mode::Syslog, or does nothing if mode is Mode::Noop.
 
virtual bool ShouldIgnore (const Operation &operation)
 Check whether the operation should be excluded from tracing. If this method returns true, the operation itself, as well as all nested operations, are not printed. Default implementation always returns false.
 

Detailed Description

Operation tracer.

All objects use tracer to report operations issued by HAL. By default, tracer sends messages to syslog with "[aspl]" prefix.

Tracer maintains per-thread operations depth counter. Nested operations are automatically indented.

If you want to change formatting, you can use one of the predefined styles or override FormatXXX() methods.

If you want to change tracer output, you can use one of the predefined modes or override Print() method.

If you want to exclude some operations from trace, you can override ShouldIgnore() method.

Definition at line 34 of file Tracer.hpp.

Member Enumeration Documentation

◆ Mode

enum class aspl::Tracer::Mode
strong

Tracing mode.

Enumerator
Noop 

No operation. Don't perform any tracing.

Stderr 

Standard error stream. Send all messages to stderr.

Syslog 

System log. Send all messages to syslog().

Custom 

Custom mode. Use if derived class does something different.

Definition at line 38 of file Tracer.hpp.

◆ Style

enum class aspl::Tracer::Style
strong

Tracing style.

Enumerator
Hierarchical 

Indent nested operations.

Flat 

No indentation.

Definition at line 58 of file Tracer.hpp.

Constructor & Destructor Documentation

◆ Tracer()

aspl::Tracer::Tracer ( Mode mode = Mode::Syslog,
Style style = Style::Hierarchical )
explicit

Initialize tracer. Mode defines where to send messages. Style defines how to format messages.

Member Function Documentation

◆ FormatMessage()

virtual std::string aspl::Tracer::FormatMessage ( const char * message,
UInt32 depth )
protectedvirtual

Format message into string. Called by default implementation of Message().

◆ FormatOperationBegin()

virtual std::string aspl::Tracer::FormatOperationBegin ( const Operation & operation,
UInt32 depth )
protectedvirtual

Format operation begin message into string. Called by default implementation of OperationBegin().

◆ FormatOperationEnd()

virtual std::string aspl::Tracer::FormatOperationEnd ( const Operation & operation,
OSStatus status,
UInt32 depth )
protectedvirtual

Format operation end message into string. Called by default implementation of OperationEnd().

◆ Message()

virtual void aspl::Tracer::Message ( const char * format,
... )
virtual

Called to print message to log. Default implementation formats arguments and calls Print().

◆ OperationBegin()

virtual void aspl::Tracer::OperationBegin ( const Operation & operation)
virtual

Called when an operations starts. Default implementation formats arguments and calls Print().

◆ OperationEnd()

virtual void virtual void aspl::Tracer::OperationEnd ( const Operation & operation,
OSStatus status )
virtual

Called when an operations completes. Zero status indicates operation success. Default implementation formats arguments and calls Print().

◆ Print()

virtual void aspl::Tracer::Print ( const char * message)
protectedvirtual

Print message somewhere. Default implementation sends message to syslog if mode is Mode::Syslog, or does nothing if mode is Mode::Noop.

◆ ShouldIgnore()

virtual bool aspl::Tracer::ShouldIgnore ( const Operation & operation)
protectedvirtual

Check whether the operation should be excluded from tracing. If this method returns true, the operation itself, as well as all nested operations, are not printed. Default implementation always returns false.


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