C12Adapter Opensource C++ Interface
MLogFileWriter Class Reference

Log file writer, one that writes information to a file. More...

Inheritance diagram for MLogFileWriter:

Public Member Functions

 MLogFileWriter ()
 Constructor that creates an uninitialized log file object.
 
 MLogFileWriter (const MStdString &fileName, unsigned maxFileSizeKB=0)
 Constructor that creates a writable log file with the given file name. More...
 
virtual ~MLogFileWriter ()
 Object destructor, close the log file.
 
unsigned GetMaxFileSizeKB () const
 Get the maximum file size in kilobytes, or zero if the maximum file size is not set. More...
 
void SetMaxFileSizeKB (unsigned size)
 Set the maximum file size in kilobytes, or zero if the maximum file size shall not be watched. More...
 
void Open (const MStdString &fileName, unsigned maxFileSizeKB=0)
 Open the file for writing, or create a new one with the given name. More...
 
virtual void Close ()
 Close the file, if it was open.
 
void Clear ()
 Clear the contents of the file, if open, and start the log over from the beginning of the file. More...
 
void WriteMessage (const char *data, size_t dataSize)
 Write the whole message to the log file.
 
void WriteMessage (const MLogFile::PacketHeader &header, const char *data)
 Send the message with the prepared header. More...
 
void WriteMessage (unsigned code, const char *message, unsigned length)
 Send the message with the specified code. More...
 
void WriteMultipleMessages (const MByteString &messages)
 Send several messages formatted as a buffer containing packets. More...
 
- Public Member Functions inherited from MLogFile
virtual ~MLogFile ()
 Object destructor, close the log file.
 
bool IsOpen () const
 Tells if the file is open. More...
 
const MStdStringGetFileName () const
 Get the file name, as set for logging. More...
 
const MStdStringGetOpenWarnings () const
 Get the warning message which might arise during opening a file and checking its contents. More...
 
void SetListener (MMonitorFile *listener)
 Sets the listener object to start handling events. More...
 
bool GetObfuscate () const
 
void SetObfuscate (bool yes)
 

Additional Inherited Members

- Public Types inherited from MLogFile
enum  {
  PAGE_HEADER_SIGNATURE = 0xA2EBBAED,
  PAGE_OBFUSCATED_HEADER_SIGNATURE = 0xA2EBBAEC,
  PAGE_TOTAL_SIZE = 0x1000,
  PAGE_HEADER_SIZE = 16,
  PAGE_FOOTER_SIZE = 4,
  PAGE_BODY_SIZE = PAGE_TOTAL_SIZE - PAGE_HEADER_SIZE - PAGE_FOOTER_SIZE,
  PACKET_HEADER_SIZE = 10,
  NUMBER_OF_PAGES_LIMIT = 0xFFFF
}
 
- Protected Member Functions inherited from MLogFile
 MLogFile ()
 Constructor that creates an uninitialized log file object.
 

Detailed Description

Log file writer, one that writes information to a file.

It can be used separately from MMonitorFile to read and produce the log with the possible circular buffer behavior.

Constructor & Destructor Documentation

MLogFileWriter::MLogFileWriter ( const MStdString fileName,
unsigned  maxFileSizeKB = 0 
)
inlineexplicit

Constructor that creates a writable log file with the given file name.

The value of maxFileSizeKB is taken into account to possibly limit the file size.

Precondition
File, if given, shall be a valid file name, or an exception is thrown. Write access to a file is attempted. If anything fails there is an exception.

Member Function Documentation

void MLogFileWriter::Clear ( )

Clear the contents of the file, if open, and start the log over from the beginning of the file.

It is not an error to clear the file which is not open.

Precondition
The file, if open, has to be open for writing, and the necessary write operations shall be successful, or the error is thrown.
unsigned MLogFileWriter::GetMaxFileSizeKB ( ) const
inline

Get the maximum file size in kilobytes, or zero if the maximum file size is not set.

Zero, there is no imposed restriction on the file size, is the default. Once the maximum size is achieved, the old data will start to disappear from the file as new data is added.

void MLogFileWriter::Open ( const MStdString fileName,
unsigned  maxFileSizeKB = 0 
)

Open the file for writing, or create a new one with the given name.

The value of maxFileSizeKB is taken into account to possibly limit the file size.

Precondition
File, if given, shall be a valid file name, the open procedure has to be achievable by the operating system, or an exception is thrown.
void MLogFileWriter::SetMaxFileSizeKB ( unsigned  size)

Set the maximum file size in kilobytes, or zero if the maximum file size shall not be watched.

Zero, there is no imposed restriction on the file size, is the default. Once the maximum size is achieved, the old data will start to disappear from the file as new data is added.

If a file exists prior the call, but its size is bigger than the imposing restriction, the file will be truncated (which can possibly take a significant amount of time).

Precondition
The size shall either be zero, no size restriction, or it shall be in range 16 to approximately 32,000 kilobytes (which corresponds to 32 megabytes), or a range expression takes place.
void MLogFileWriter::WriteMessage ( const MLogFile::PacketHeader header,
const char *  data 
)

Send the message with the prepared header.

Precondition
Header shall be valid, length corresponds to the given data pointer. Also, any file write-related exception can be thrown.
void MLogFileWriter::WriteMessage ( unsigned  code,
const char *  message,
unsigned  length 
)

Send the message with the specified code.

Precondition
Code is valid and message has a valid format. The check is done in the debugging version that the code fits in range 0 to 0xFFFF. Also, any file write-related exception can be thrown.
void MLogFileWriter::WriteMultipleMessages ( const MByteString messages)

Send several messages formatted as a buffer containing packets.

Precondition
Messages have a valid format, no part of a message can be written with this service, only a number of complete messages. There is a debug check for a format error. Also, any file write-related exception can be thrown.