The Vish Visualization Shell 0.3
Vish
Classes | Public Member Functions | Static Public Member Functions | List of all members
Wizt::VLogger Class Reference

Log messages, usually for analysing the program's internal flow for debugging purposes. More...

#include <ocean/plankton/VLogger.hpp>

Inheritance diagram for Wizt::VLogger:
MemCore::ReferenceBase< VLogger > Wizt::VStreamLogger::Logger

Classes

struct  Context
 Set logging context with auto-cleanup. More...
 
class  Indent
 A class for setting a temporary increment of the indentation of logging text; it allows to indent logged text automatically during the lifetime of the Indent object. More...
 
class  State
 Describes a thread-local state of the logging process. More...
 

Public Member Functions

bool activate ()
 Activate this VLogger object.
 
virtual void printmsg (const string &text, int verbosity, int indent_spaces, const string &srcfilename, unsigned linenumber, const WeakPtr< VTask > &ThreadID, const string &funcname)
 Message output function.
 
 VLogger ()
 Constructs and adds a logging object.
 
 ~VLogger ()
 Destructor.
 
- Public Member Functions inherited from MemCore::ReferenceBase< VLogger >
auto getObjectCountID () const noexcept
 Get a unique ID for this object in the given domain.
 
bool isIdentical (const WeakPtr< VLogger, VLogger > &PossibleSelf) const noexcept
 Check if this object is identical to the one used by the given pointer.
 
void mkAutoDestructive ()
 Marks this object as being automatically destructed, e.g.
 
refcount_t refcount () const noexcept
 The strong reference count.
 
 ReferenceBase (VLogger *that) noexcept
 Constructor, initializes reference counter to zero.
 
const auto & self () const
 Return weak pointer to the object self.
 
refcount_t wrefcount () const noexcept
 The weak reference count.
 

Static Public Member Functions

static void print (const string &text, int verbosity, int indent_spaces, const string &srcfilename, unsigned linenumber, const WeakPtr< VTask > &ThreadID, const string &funcname)
 Verbose print function.
 
static void print (int verbosity, const string &s)
 Simplified print function.
 
static void printf (int verbosity, const char *format,...)
 Print formatted function with parameters.
 

Additional Inherited Members

- Public Types inherited from MemCore::ReferenceBase< VLogger >
using reference_domain_t = VLogger
 The type of the base class.
 
using SelfPtr_t = WeakPtr< VLogger, VLogger >
 Type for a pointer to this object itself.
 
- Protected Member Functions inherited from MemCore::ReferenceBase< VLogger >
virtual void extremeUnction ()
 A virtual function that will be called just before the object is destroyed.
 
ReferenceBaseoperator= (const ReferenceBase &R)
 Protected assignment operator (should not be called).
 
void suicide ()
 Delete this.
 
virtual ~ReferenceBase ()
 Virtual destructor.
 

Detailed Description

Log messages, usually for analysing the program's internal flow for debugging purposes.

While using of debuggers is helpful to trace down fatal program errors leading to segmentation faults and core dumps, debugging tools are not too effective to analyse and verify the execution flow of a program. Logical errors - in contrast to simple programming errors - are hardly determinable using runtime debuggers since they only show a certain state of a program, but not the execution history. The ability to log the program's execution flow is the more effective approach for tracing higher-level errors, especcially in a multithreaded context.

This class only provides an abstraction interface to various output facilities. Multiple clients may connect to the logging instance.

The API is intentionally as simple as possible, such that application code just needs to be instrumented with print() or printf() calls. Only required addition is the specification of a verbosity level. The higher the verbosity level, the more detailed the information is, and it is the duty of the implementation of a VLogger to display logging information only up to a certain verbosity level.

The VLogger class implements a function call stack for each thread and keep track of a context when issuing print statements. This context contains the current function name, source file name, line number and indentation level. The context may be setup automatically by some external source code instrumentation tool which inserts certain code lines. However, manual instrumentation might be more effective since there doesn't need to be a 1:1 correspondence. For instance, one specific line in a source code might emit multiple logging lines, or a function should not show up explicitely since the calling function is the one providing the relevant context.

Class Derivation Example:

class MyLogger : public VLogger
{
void printmsg(const string&text,
int verbosity,
int indent_spaces,
const string&srcfilename,
unsigned linenumber,
const WeakPtr<VTask>&ThreadID,
const string&funcname
) override;
};
main()
{
RefPtr<MyLogger> MainLogger = new MyLogger();
MainLogger->activate();
}
A reference counting pointer class which keeps objects alive as long as strong pointers to these obje...
Definition RefPtr.hpp:405
A pointer class which behaves like native C++ pointers, but knows about the lifetime of the reference...
Definition RefPtr.hpp:82
Log messages, usually for analysing the program's internal flow for debugging purposes.
Definition VLogger.hpp:105
    bool activate();
Todo:
Provide a std::ostream interface . But should be in a separate header file.

Member Function Documentation

◆ activate()

bool Wizt::VLogger::activate ( )

Activate this VLogger object.

It must be referenced via a strongptr from some application code.

References MemCore::ReferenceBase< VLogger >::self().

◆ print()

void Wizt::VLogger::print ( const string &  text,
int  verbosity,
int  indent_spaces,
const string &  srcfilename,
unsigned  linenumber,
const WeakPtr< VTask > &  ThreadID,
const string &  funcname 
)
static

Verbose print function.

All arguments are broadcasted to all activated instances of VLogger objects.

Parameters
textthe actual text to be printed
verbositythe verbosity level
indent_spaceshow many spaces to indent at the beginning of the line?
srcfilenamethe file name of the source that issues this command, usually FILE
linenumberthe line number of the source file, usually LINE
ThreadIDan identifier for the thread issuing the message
funcnamethe function context for which this function was called.

Referenced by print(), and printf().

◆ printmsg()

void Wizt::VLogger::printmsg ( const string &  text,
int  verbosity,
int  indent_spaces,
const string &  srcfilename,
unsigned  linenumber,
const WeakPtr< VTask > &  ThreadID,
const string &  funcname 
)
virtual

Message output function.

By default, prints message on standard output.

Parameters
textthe actual text to be printed
verbositythe verbosity level
indent_spaceshow many spaces to indent at the beginning of the line?
srcfilenamethe file name of the source that issues this command, usually FILE
linenumberthe line number of the source file, usually LINE
ThreadIDan identifier for the thread issuing the message
funcnamecurrent function (last registered for debugging)

Reimplemented in Wizt::VStreamLogger::Logger.

References printf().