JUCE
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Public Member Functions | Static Public Member Functions
FileLogger Class Reference

A simple implemenation of a Logger that writes to a file. More...

Inherits Logger.

List of all members.

Public Member Functions

 FileLogger (const File &fileToWriteTo, const String &welcomeMessage, const int maxInitialFileSizeBytes=128 *1024)
 Creates a FileLogger for a given file.
 ~FileLogger ()
 Destructor.
void logMessage (const String &message)
 This is overloaded by subclasses to implement custom logging behaviour.
File getLogFile () const

Static Public Member Functions

static FileLoggercreateDefaultAppLogger (const String &logFileSubDirectoryName, const String &logFileName, const String &welcomeMessage, const int maxInitialFileSizeBytes=128 *1024)
 Helper function to create a log file in the correct place for this platform.

Detailed Description

A simple implemenation of a Logger that writes to a file.

See also:
Logger

Constructor & Destructor Documentation

FileLogger::FileLogger ( const File fileToWriteTo,
const String welcomeMessage,
const int  maxInitialFileSizeBytes = 128 *1024 
)

Creates a FileLogger for a given file.

Parameters:
fileToWriteTothe file that to use - new messages will be appended to the file. If the file doesn't exist, it will be created, along with any parent directories that are needed.
welcomeMessagewhen opened, the logger will write a header to the log, along with the current date and time, and this welcome message
maxInitialFileSizeBytesif this is zero or greater, then if the file already exists but is larger than this number of bytes, then the start of the file will be truncated to keep the size down. This prevents a log file getting ridiculously large over time. The file will be truncated at a new-line boundary. If this value is less than zero, no size limit will be imposed; if it's zero, the file will always be deleted. Note that the size is only checked once when this object is created - any logging that is done later will be appended without any checking

Destructor.


Member Function Documentation

void FileLogger::logMessage ( const String message) [virtual]

This is overloaded by subclasses to implement custom logging behaviour.

See also:
setCurrentLogger

Implements Logger.

static FileLogger* FileLogger::createDefaultAppLogger ( const String logFileSubDirectoryName,
const String logFileName,
const String welcomeMessage,
const int  maxInitialFileSizeBytes = 128 *1024 
) [static]

Helper function to create a log file in the correct place for this platform.

On Windows this will return a logger with a path such as: c:\Documents and Settings\username\Application Data\[logFileSubDirectoryName]\[logFileName]

On the Mac it'll create something like: ~/Library/Logs/[logFileName]

The method might return 0 if the file can't be created for some reason.

Parameters:
logFileSubDirectoryNameif a subdirectory is needed, this is what it will be called - it's best to use the something like the name of your application here.
logFileNamethe name of the file to create, e.g. "MyAppLog.txt". Don't just call it "log.txt" because if it goes in a directory with logs from other applications (as it will do on the Mac) then no-one will know which one is yours!
welcomeMessagea message that will be written to the log when it's opened.
maxInitialFileSizeBytes(see the FileLogger constructor for more info on this)

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