Workspace 6.21.5
Public Member Functions | List of all members
LogToFile Class Reference

LogStream subclass for directing a log stream to file. More...

#include <Workspace/DataExecution/Logging/logtofile.h>

Inheritance diagram for LogToFile:
[legend]

Public Member Functions

 LogToFile (const QString &fileName, bool append=false)
 
 ~LogToFile () override
 
void flush () override
 
QString getFileName () const
 
bool getPrefixTimestamp () const
 
bool isStreamOkay () const override
 
void setPrefixTimestamp (bool enable)
 
- Public Member Functions inherited from LogStream
virtual ~LogStream ()
 
virtual void flush ()=0
 
virtual bool isStreamOkay () const =0
 
void logText (const QString &msg, const QDateTime &timestamp)
 

Detailed Description

Because logging information is often needed as a diagnostic aid when developing operations, all calls to logText() are immediately followed by a call to flush(). This ensures that logged text is seen as soon as possible and it minimizes the chances of logged text being lost in the event of a crash.

Constructor & Destructor Documentation

◆ LogToFile()

LogToFile ( const QString &  fileName,
bool  append = false 
)
Parameters
fileNameThe name of the file where logged text should be sent.
appendIf a file with the specified fileName already exists, this parameter controls whether text will be appended to it (append == true) or whether the old contents are discarded (append == false).

The constructor attempts to open a file with the specified fileName for writing. No check is performed for whether or not this succeeds, so if clients want to know this they will have to call isStreamOkay().

◆ ~LogToFile()

~LogToFile ( )
override

Member Function Documentation

◆ flush()

void flush ( )
overridevirtual

Clients would not normally need to call this function, but if for some reason they want to be sure that all logged text has been sent to where it needs to go before performing some task, they can call flush(). When flush() returns, all underlying streams and buffers associated with the LogStream object will have been flushed to disk, etc.

Implements LogStream.

◆ getFileName()

QString getFileName ( ) const

◆ getPrefixTimestamp()

bool getPrefixTimestamp ( ) const

◆ isStreamOkay()

bool isStreamOkay ( ) const
overridevirtual
Returns
True if the stream is able to accept text for writing.

Implements LogStream.

◆ setPrefixTimestamp()

void setPrefixTimestamp ( bool  enable)