Loading...
Searching...
No Matches
juce::FileLogger Class Reference

## Detailed Description

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

See also
  Logger

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

- juce_core/logging/juce_FileLogger.h

Inheritance diagram for juce::FileLogger:

## Public Member Functions

| FileLogger (const File &fileToWriteTo, const String &welcomeMessage, const int64 maxInitialFileSizeBytes=128 *1024)
| Creates a FileLogger for a given file.
| ~FileLogger () override
| Destructor.
const File & | getLogFile () const noexcept
| Returns the file that this logger is writing to.
void | logMessage (const String &) override
| This is overloaded by subclasses to implement custom logging behaviour.
Public Member Functions inherited from juce::Logger
virtual | ~Logger ()
| Destructor.

## Static Public Member Functions

static FileLogger * | createDefaultAppLogger (const String &logFileSubDirectoryName, const String &logFileName, const String &welcomeMessage, const int64 maxInitialFileSizeBytes=128 *1024)
| Helper function to create a log file in the correct place for this platform.
static FileLogger * | createDateStampedLogger (const String &logFileSubDirectoryName, const String &logFileNameRoot, const String &logFileNameSuffix, const String &welcomeMessage)
| Helper function to create a log file in the correct place for this platform.
static File | getSystemLogFileFolder ()
| Returns an OS-specific folder where log-files should be stored.
static void | trimFileSize (const File &file, int64 maxFileSize)
| This is a utility function which removes lines from the start of a text file to make sure that its total size is below the given size.
Static Public Member Functions inherited from juce::Logger
static void JUCE_CALLTYPE | setCurrentLogger (Logger *newLogger) noexcept
| Sets the current logging class to use.
static Logger *JUCE_CALLTYPE | getCurrentLogger () noexcept
| Returns the current logger, or nullptr if no custom logger has been set.
static void JUCE_CALLTYPE | writeToLog (const String &message)
| Writes a string to the current logger.
static void JUCE_CALLTYPE | outputDebugString (const String &text)
| Writes a message to the standard error stream.

## Additional Inherited Members

Protected Member Functions inherited from juce::Logger
| Logger ()

## Constructors and Destructors

## FileLogger()

juce::FileLogger::FileLogger | ( | const File & | fileToWriteTo,
|  | const String & | welcomeMessage,
|  | const int64 | maxInitialFileSizeBytes = 128 *1024 )

Creates a FileLogger for a given file.

Parameters

  fileToWriteTo | the 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.
  welcomeMessage | when opened, the logger will write a header to the log, along with the current date and time, and this welcome message

  maxInitialFileSizeBytes

  if 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

Referenced by createDateStampedLogger(), createDefaultAppLogger(), and trimFileSize().

## ~FileLogger()

juce::FileLogger::~FileLogger | ( |  | ) |

override

Destructor.

## Member Functions

## getLogFile()

const File & juce::FileLogger::getLogFile | ( |  | ) | const

inline noexcept

Returns the file that this logger is writing to.

## createDefaultAppLogger()

FileLogger * juce::FileLogger::createDefaultAppLogger | ( | const String & | logFileSubDirectoryName,
|  | const String & | logFileName,
|  | const String & | welcomeMessage,
|  | const int64 | maxInitialFileSizeBytes = 128 *1024 )

static

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

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

Parameters

  logFileSubDirectoryName | the name of the subdirectory to create inside the logs folder (as returned by getSystemLogFileFolder). It's best to use something like the name of your application here.
  logFileName | the name of the file to create, e.g. "MyAppLog.txt".
  welcomeMessage | a message that will be written to the log when it's opened.
  maxInitialFileSizeBytes | (see the FileLogger constructor for more info on this)

References FileLogger().

## createDateStampedLogger()

FileLogger * juce::FileLogger::createDateStampedLogger | ( | const String & | logFileSubDirectoryName,
|  | const String & | logFileNameRoot,
|  | const String & | logFileNameSuffix,
|  | const String & | welcomeMessage )

static

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

The filename used is based on the root and suffix strings provided, along with a time and date string, meaning that a new, empty log file will be always be created rather than appending to an existing one.

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

Parameters

  logFileSubDirectoryName | the name of the subdirectory to create inside the logs folder (as returned by getSystemLogFileFolder). It's best to use something like the name of your application here.
  logFileNameRoot | the start of the filename to use, e.g. "MyAppLog_". This will have a timestamp and the logFileNameSuffix appended to it
  logFileNameSuffix | the file suffix to use, e.g. ".txt"
  welcomeMessage | a message that will be written to the log when it's opened.

References FileLogger().

## getSystemLogFileFolder()

File juce::FileLogger::getSystemLogFileFolder | ( |  | ) |

static

Returns an OS-specific folder where log-files should be stored.

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/[logFileSubDirectoryName]/[logFileName]

See also
  createDefaultAppLogger

## logMessage()

void juce::FileLogger::logMessage | ( | const String & | message | ) |

override virtual

This is overloaded by subclasses to implement custom logging behaviour.

See also
  setCurrentLogger

Implements juce::Logger.

## trimFileSize()

void juce::FileLogger::trimFileSize | ( | const File & | file,
|  | int64 | maxFileSize )

static

This is a utility function which removes lines from the start of a text file to make sure that its total size is below the given size.

References FileLogger().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited