AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
agx::LogStream Class Reference

Class for printing out messages to console, file, virtual method and or a callback function. More...

#include <LogStream.h>

+ Inheritance diagram for agx::LogStream:

Public Types

typedef void(* CallbackFunction_t) (const char *, unsigned int)
 
enum  OutputMode { CERR = 1 , COUT = 2 , FILE = 4 , FUNCTION = 8 }
 Enums used to specify the output mode used. These can be OR:ed together. More...
 

Public Member Functions

 LogStream ()
 Constructor.
 
virtual ~LogStream ()
 Flush and empty all buffers, and then remove the allocated buffers.
 
void appendOutputMode (short modemask)
 OR:s together the active outputmode with modemask.
 
void clearOutputMode (void)
 Resets the active output modes to none.
 
void close (void)
 
void flush ()
 
CallbackFunction_t getCallback ()
 
const agx::String & getDateFormat () const
 
bool getEnableDate () const
 
bool getEnableThreadId () const
 
agx::String getFilename () const
 
int getOutputMode (void)
 Returns the active outputmode.
 
bool haveOpenFile () const
 
bool isActive (OutputMode modemask)
 Returns true if the modemask is set as the active output mode.
 
virtual void message (const char *msg, unsigned int length)
 This method will be called whenever there is a message ready for output.
 
bool open (const agx::String &name)
 Open a specified file as a log.
 
void setCallback (CallbackFunction_t f)
 Sets the function that will be called if FUNCTION is set as outputmode.
 
void setDateFormat (const agx::String &date_format)
 Specify the format of the date/time string that getTimeString() will return Look at strftime for examples of how to specify the date.
 
void setEnableDate (bool flag)
 If flag == true, the date in the specified date format will be added prior to each message.
 
void setEnableThreadId (bool flag)
 If set to true, the messages will be prefixed with the id of the thread that generates the message.
 
void setOutputMode (short modemask)
 Set the active outputmode to modemask.
 

Static Public Member Functions

static agx::String getTimeString (const agx::String &dateFormat="", bool logTimeWithMilliseconds=true)
 

Protected Member Functions

 LogStream (const LogStream &)
 
LogStream & operator= (const LogStream &)
 
size_t write (const char *msg, std::streamsize count)
 

Protected Attributes

CallbackFunction_t m_callback
 
::FILE * m_file
 
agx::String m_filename
 
bool m_isOpen
 
int m_mode
 

Detailed Description

Class for printing out messages to console, file, virtual method and or a callback function.

Definition at line 44 of file LogStream.h.

Member Typedef Documentation

◆ CallbackFunction_t

typedef void(* agx::LogStream::CallbackFunction_t) (const char *, unsigned int)

Definition at line 53 of file LogStream.h.

Member Enumeration Documentation

◆ OutputMode

Enums used to specify the output mode used. These can be OR:ed together.

Enumerator
CERR 
COUT 
FILE 
FUNCTION 

Definition at line 85 of file LogStream.h.

Constructor & Destructor Documentation

◆ LogStream() [1/2]

agx::LogStream::LogStream ( )

Constructor.

◆ ~LogStream()

virtual agx::LogStream::~LogStream ( )
virtual

Flush and empty all buffers, and then remove the allocated buffers.

◆ LogStream() [2/2]

agx::LogStream::LogStream ( const LogStream &  )
protected

Member Function Documentation

◆ appendOutputMode()

void agx::LogStream::appendOutputMode ( short  modemask)

OR:s together the active outputmode with modemask.

◆ clearOutputMode()

void agx::LogStream::clearOutputMode ( void  )

Resets the active output modes to none.

◆ close()

void agx::LogStream::close ( void  )

◆ flush()

void agx::LogStream::flush ( )

◆ getCallback()

CallbackFunction_t agx::LogStream::getCallback ( )

◆ getDateFormat()

const agx::String & agx::LogStream::getDateFormat ( ) const
Returns
the date format used for specifying the output format of the getTimeString()

◆ getEnableDate()

bool agx::LogStream::getEnableDate ( ) const

◆ getEnableThreadId()

bool agx::LogStream::getEnableThreadId ( ) const

◆ getFilename()

agx::String agx::LogStream::getFilename ( ) const

◆ getOutputMode()

int agx::LogStream::getOutputMode ( void  )

Returns the active outputmode.

◆ getTimeString()

static agx::String agx::LogStream::getTimeString ( const agx::String &  dateFormat = "",
bool  logTimeWithMilliseconds = true 
)
static
Parameters
dateFormat- Format in date (if logTimeWithMilliseconds==false) as being used by the method strftime()
logTimeWithMilliseconds- If true (default) the date string will be reported in milliseconds
Returns
the current time in the specified time format

◆ haveOpenFile()

bool agx::LogStream::haveOpenFile ( ) const
Returns
true if a file is open

◆ isActive()

bool agx::LogStream::isActive ( OutputMode  modemask)

Returns true if the modemask is set as the active output mode.

◆ message()

virtual void agx::LogStream::message ( const char *  msg,
unsigned int  length 
)
virtual

This method will be called whenever there is a message ready for output.

Derive from this class and implement this method.

◆ open()

bool agx::LogStream::open ( const agx::String &  name)

Open a specified file as a log.

◆ operator=()

LogStream & agx::LogStream::operator= ( const LogStream &  )
protected

◆ setCallback()

void agx::LogStream::setCallback ( CallbackFunction_t  f)

Sets the function that will be called if FUNCTION is set as outputmode.

◆ setDateFormat()

void agx::LogStream::setDateFormat ( const agx::String &  date_format)

Specify the format of the date/time string that getTimeString() will return Look at strftime for examples of how to specify the date.

Default is "%X" (hh:mm:ss)

◆ setEnableDate()

void agx::LogStream::setEnableDate ( bool  flag)

If flag == true, the date in the specified date format will be added prior to each message.

◆ setEnableThreadId()

void agx::LogStream::setEnableThreadId ( bool  flag)

If set to true, the messages will be prefixed with the id of the thread that generates the message.

◆ setOutputMode()

void agx::LogStream::setOutputMode ( short  modemask)

Set the active outputmode to modemask.

◆ write()

size_t agx::LogStream::write ( const char *  msg,
std::streamsize  count 
)
protected

Member Data Documentation

◆ m_callback

CallbackFunction_t agx::LogStream::m_callback
protected

Definition at line 137 of file LogStream.h.

◆ m_file

::FILE* agx::LogStream::m_file
protected

Definition at line 140 of file LogStream.h.

◆ m_filename

agx::String agx::LogStream::m_filename
protected

Definition at line 142 of file LogStream.h.

◆ m_isOpen

bool agx::LogStream::m_isOpen
protected

Definition at line 141 of file LogStream.h.

◆ m_mode

int agx::LogStream::m_mode
protected

Definition at line 139 of file LogStream.h.


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