LRAUV  revA
FileLogWriter Class Reference

Wraps around another LogWriter to write LogEntries to a file. More...

#include <FileLogWriter.h>

Inheritance diagram for FileLogWriter:
Collaboration diagram for FileLogWriter:

Public Types

enum  FlushFreq { FLUSH_ONCE = 0, FLUSH_PER_CYCLE = 1, FLUSH_PER_WRITE }
 
- Public Types inherited from LogWriter
enum  ServiceType {
  NO_SERVICE = -1, SERVICE_COURIER, SERVICE_EXPRESS, SERVICE_PRIORITY,
  SERVICE_NORMAL, SERVICE_BULK, SERVICE_COUNT, SERVICE_MULTI
}
 

Public Member Functions

 FileLogWriter (const Str &filename, LogWriter *logWriter, const bool append=false, FileEncoder *fileEncoder=NULL)
 Constructor with filename & specified flushFreq. More...
 
 FileLogWriter (FILE *file, LogWriter *logWriter)
 Constructor with FILE. More...
 
virtual ~FileLogWriter ()
 Destructor, closes file if open. More...
 
virtual void resetInputs ()
 Reset cached input settings. More...
 
virtual bool valid (void)
 Is the LogWriter valid? More...
 
virtual unsigned int write (const LogEntry *entry, const Unit *unit=NULL)
 Write. More...
 
virtual void endCycle ()
 If flushFreq_ is FLUSH_PER_CYCLE, this causes an output flush. More...
 
unsigned int getBytesInFile (void)
 Accessors. More...
 
unsigned int getEntriesWritten (void)
 
virtual const StrgetFilename ()
 
void resetFilename (const Str &filename)
 
bool isWritable (void)
 Keep track of whether the stream is open. More...
 
- Public Member Functions inherited from LogWriter
virtual ~LogWriter ()
 Destructor. More...
 
virtual unsigned int writeHeader ()
 Write the log header, if any. More...
 
virtual void setOutStream (OutStream &outStream)
 Sets the OutStream. More...
 
virtual bool isValid ()
 Return true if logStream_ is available. More...
 
virtual unsigned int writeFooter ()
 Write the log footer, if any. More...
 
virtual void config (Logger &logger)
 Configure from a config file. More...
 
void addParent ()
 
void removeParent ()
 
int getParentCount ()
 
virtual void activate ()
 
virtual void deactivate ()
 
virtual bool isActive ()
 
virtual void lockWrites ()
 
virtual void unlockWrites ()
 
- Public Member Functions inherited from HasFilename
virtual ~HasFilename ()
 

Protected Member Functions

bool open (const char *filename, const bool append)
 Open the stream to the named file. More...
 
void close (void)
 Close the currently open file. More...
 
void setFlushFreq (const FlushFreq flushFreq)
 
FileEncodergetFileEncoder ()
 
void setFilename (const Str &filename)
 
- Protected Member Functions inherited from LogWriter
 LogWriter ()
 Protected constructor for pure virtual class. More...
 
 LogWriter (OutStream &outStream)
 Protected constructor for pure virtual class. More...
 
- Protected Member Functions inherited from HasFilename
 HasFilename ()
 

Protected Attributes

LogWriterlogWriter_
 The LogWriter that does the actual writing. More...
 
- Protected Attributes inherited from LogWriter
OutStreamlogStream_
 Stores an OutStream. More...
 
bool wroteHeader_
 
bool wroteFooter_
 
Mutex writeMutex_
 
int parentCount_
 
bool active_
 

Private Member Functions

 FileLogWriter (const FileLogWriter &old)
 

Private Attributes

FileOutStream fileStream_
 The output file stream. More...
 
unsigned int entriesWritten_
 Total entries written. More...
 
unsigned int bytesInFile_
 Total bytes written. More...
 
bool initFilename_
 True if a file name is specified in constructor. More...
 
Str filename_
 Name of the current file. More...
 
FlushFreq flushFreq_
 
bool writtenInCycle_
 
FileEncoderfileEncoder_
 

Additional Inherited Members

- Static Public Member Functions inherited from LogWriter
static ServiceType Str2ServiceType (const char *const serviceTypeStr, int len=-1)
 
static const char * ServiceType2Str (LogWriter::ServiceType serviceType)
 
static size_t ServiceType2Strlen (LogWriter::ServiceType serviceType)
 
- Static Public Attributes inherited from LogWriter
static const char *const SERVICE_TYPE_STRS [SERVICE_COUNT]
 
static size_t const SERVICE_TYPE_STRLEN [SERVICE_COUNT]
 

Detailed Description

Wraps around another LogWriter to write LogEntries to a file.

Designed around assumption that it always has a log file open, though it does keep track of whether the stream is open or close, which it uses to determine if it's valid.

Constructor & Destructor Documentation

FileLogWriter::FileLogWriter ( const Str filename,
LogWriter logWriter,
const bool  append = false,
FileEncoder fileEncoder = NULL 
)

Constructor with filename & specified flushFreq.

Parameters
filenameName of file to write to
logWriterlogWriter that provides input for file logging
appendif true, append to file, otherwise overwrite.
fileEncoderoptional encoder to run whenever the file closes

References LogWriter::addParent(), Str::cStr(), fileStream_, initFilename_, logWriter_, open(), and LogWriter::setOutStream().

FileLogWriter::FileLogWriter ( FILE *  file,
LogWriter logWriter 
)

Constructor with FILE.

Parameters
fileFILE to write to
logWriterlogWriter that provides input for file logging

References LogWriter::addParent(), fileStream_, logWriter_, LogWriter::setOutStream(), and LogWriter::writeHeader().

FileLogWriter::~FileLogWriter ( )
virtual

Destructor, closes file if open.

Destructor.

Closes file if open

References close(), fileEncoder_, LogWriter::getParentCount(), logWriter_, and LogWriter::removeParent().

FileLogWriter::FileLogWriter ( const FileLogWriter old)
private

Member Function Documentation

void FileLogWriter::close ( void  )
protected
void FileLogWriter::endCycle ( )
virtual

If flushFreq_ is FLUSH_PER_CYCLE, this causes an output flush.

Reimplemented from LogWriter.

References fileStream_, FileOutStream::flush(), FLUSH_PER_CYCLE, flushFreq_, and writtenInCycle_.

unsigned int FileLogWriter::getBytesInFile ( void  )
inline

Accessors.

References bytesInFile_.

Referenced by SplitFileLogWriter::write().

unsigned int FileLogWriter::getEntriesWritten ( void  )
inline

References entriesWritten_.

FileEncoder* FileLogWriter::getFileEncoder ( )
inlineprotected

References fileEncoder_.

Referenced by SplitFileLogWriter::split().

virtual const Str& FileLogWriter::getFilename ( )
inlinevirtual

Implements HasFilename.

References filename_.

Referenced by SplitFileLogWriter::split().

bool FileLogWriter::isWritable ( void  )
inline

Keep track of whether the stream is open.

References fileStream_, and FileOutStream::isWritable().

Referenced by close(), open(), SplitFileLogWriter::split(), valid(), SplitFileLogWriter::write(), and write().

bool FileLogWriter::open ( const char *  filename,
const bool  append 
)
protected

Open the stream to the named file.

Open the given file.

Parameters
filenameName of system log.
appendIf true, open the file in append mode (otherwise overwrite)

References bytesInFile_, close(), entriesWritten_, filename_, fileStream_, isWritable(), logWriter_, FileOutStream::open(), LogWriter::writeHeader(), and LogWriter::wroteFooter_.

Referenced by FileLogWriter(), resetFilename(), SplitFileLogWriter::split(), and SplitFileLogWriter::write().

void FileLogWriter::resetFilename ( const Str filename)

References close(), Str::cStr(), and open().

Referenced by Supervisor::RestartLogs().

void FileLogWriter::resetInputs ( )
virtual

Reset cached input settings.

Reimplemented from LogWriter.

References logWriter_, and LogWriter::resetInputs().

void FileLogWriter::setFilename ( const Str filename)
inlineprotected

References filename_.

void FileLogWriter::setFlushFreq ( const FlushFreq  flushFreq)
inlineprotected

References flushFreq_.

virtual bool FileLogWriter::valid ( void  )
inlinevirtual

Is the LogWriter valid?

References isWritable().

unsigned int FileLogWriter::write ( const LogEntry entry,
const Unit unit = NULL 
)
virtual

Member Data Documentation

unsigned int FileLogWriter::bytesInFile_
private

Total bytes written.

Referenced by close(), getBytesInFile(), open(), and write().

unsigned int FileLogWriter::entriesWritten_
private

Total entries written.

Referenced by getEntriesWritten(), open(), and write().

FileEncoder* FileLogWriter::fileEncoder_
private
Str FileLogWriter::filename_
private

Name of the current file.

Referenced by close(), getFilename(), open(), and setFilename().

FileOutStream FileLogWriter::fileStream_
private

The output file stream.

Referenced by close(), endCycle(), FileLogWriter(), isWritable(), open(), and write().

FlushFreq FileLogWriter::flushFreq_
private

Referenced by endCycle(), setFlushFreq(), and write().

bool FileLogWriter::initFilename_
private

True if a file name is specified in constructor.

Referenced by close(), and FileLogWriter().

LogWriter* FileLogWriter::logWriter_
protected
bool FileLogWriter::writtenInCycle_
private

Referenced by endCycle(), and write().


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