Logger¶
The logger class.
Inherited by the following classes: SparkyStudios::Audio::Amplitude::ConsoleLogger, SparkyStudios::Audio::Amplitude::FileLogger, SparkyStudios::Audio::Amplitude::LogcatLogger, SparkyStudios::Audio::Amplitude::NSLogger, SparkyStudios::Audio::Amplitude::NullLogger
Detailed Description¶
Base class used to perform logging. Implementations of this class can display or store log messages wherever they are needed.
Messages logged from the audio thread (see Logger::ScopedAudioThread) are never written there: they are copied into a lock-free queue, and written by the next Flush(), which the engine calls once per frame. Messages logged from any other thread are written at once, after the ones still queued, so the order is kept.
Warning:
The global logger is meant to be installed once during engine setup. It is not meant to be swapped, or destroyed while the engine runs. The installed logger must be kept alive until the engine is deinitialized.
Classes¶
| Type | Name |
|---|---|
| class | ScopedAudioThread Marks the calling thread as an audio thread while it is alive. |
Public Static Attributes¶
| Type | Name |
|---|---|
| AmSize | kMaxQueuedMessageLength = 256The longest message, in characters, kept when it is logged from an audio thread. A longer one is cut, and ends with "..." to show it. |
Public Functions¶
| Type | Name |
|---|---|
| void | Critical (const char * file, int line, const AmString & message) Logs a critical message. |
| void | Debug (const char * file, int line, const AmString & message) Logs a debug message. |
| void | Error (const char * file, int line, const AmString & message) Logs an error message. |
| void | Flush () Writes the messages queued from the audio thread. |
| void | Info (const char * file, int line, const AmString & message) Logs an informational message. |
| Logger () Creates the logger. | |
| void | Success (const char * file, int line, const AmString & message) Logs a success message. |
| void | Warning (const char * file, int line, const AmString & message) Logs a warning message. |
| void | Write (eLogMessageLevel level, const char * file, int line, const char * message, AmSize length) Logs a message with this logger. |
| virtual | ~Logger () Destroys the logger, and unregisters it if it is the global one. |
Public Static Functions¶
| Type | Name |
|---|---|
| void | Emit (eLogMessageLevel level, const char * file, int line, const char * message, AmSize length) Logs a message with the global logger, if there is one. |
| Logger * | GetLogger () Gets the logger instance to use when calling amLogger . |
| void | SetLogger (Logger * loggerInstance) Sets the logger instance to use when calling amLogger . |
Protected Functions¶
| Type | Name |
|---|---|
| virtual void | Log (eLogMessageLevel level, const char * file, int line, const AmString & message) = 0 Logs a message with the given level. |
Public Static Attributes Documentation¶
kMaxQueuedMessageLength
The longest message, in characters, kept when it is logged from an audio thread. A longer one is cut, and ends with "..." to show it.
Public Functions Documentation¶
Critical
Logs a critical message.
Parameters:
-
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message to log.
Debug
Logs a debug message.
Parameters:
-
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message to log.
Error
Logs an error message.
Parameters:
-
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message to log.
Flush
Writes the messages queued from the audio thread.
Safe to call from any thread but an audio thread, and from several at once: writes are serialized. If the queue overflowed, one warning reports how many messages were dropped.
Info
Logs an informational message.
Parameters:
-
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message to log.
Success
Logs a success message.
Parameters:
-
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message to log.
Warning
Logs a warning message.
Parameters:
-
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message to log.
Write
Logs a message with this logger.
void Amplitude::Logger::Write (
eLogMessageLevel level,
const char * file,
int line,
const char * message,
AmSize length
)
Prefer the amLog macros. From an audio thread, the message is queued (and cut to kMaxQueuedMessageLength characters, ending with "..."); from any other thread, it is written at once.
Parameters:
-
levelThe level of the log message. -
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message, not necessarily null-terminated. -
lengthThe length ofmessage.
~Logger
Destroys the logger, and unregisters it if it is the global one.
Messages still queued are lost: a logger that writes somewhere should call Flush() in its own destructor, while it can still write.
Public Static Functions Documentation¶
Emit
Logs a message with the global logger, if there is one.
static void Amplitude::Logger::Emit (
eLogMessageLevel level,
const char * file,
int line,
const char * message,
AmSize length
)
This is what the amLog macros call: the global logger is read once, so it cannot go away between the test and the call.
Parameters:
-
levelThe level of the log message. -
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message, not necessarily null-terminated. -
lengthThe length ofmessage.
GetLogger
Gets the logger instance to use when calling amLogger .
Returns:
The logger instance.
SetLogger
Sets the logger instance to use when calling amLogger .
Messages still queued on the logger being replaced are written first.
Call it before initializing the engine, and again (with the previous logger, or nullptr) only after the engine is deinitialized.
Parameters:
-
loggerInstanceThe logger instance.
Protected Functions Documentation¶
Log
Logs a message with the given level.
virtual void Amplitude::Logger::Log (
eLogMessageLevel level,
const char * file,
int line,
const AmString & message
) = 0
Parameters:
-
levelThe level of the log message. -
fileThe file where the message was logged. -
lineThe line where the message was logged. -
messageThe message to log.
The documentation for this class was generated from the following file: include/SparkyStudios/Audio/Amplitude/IO/Log.h