C++ API
To do a log, simply call the ULog::Logger::log
function,
which looks like this:
template<typename... args>
static void log(const char* message, LogType type, args&&... argv) noexcept
It takes a message as a string, a LogType
enum that
specifies the type of the message and a list of variadic arguments which
can contain any std::ostream
compatible types.
The LogType
enum looks like this:
enum LogType
{
,
ULOG_LOG_TYPE_WARNING,
ULOG_LOG_TYPE_ERROR,
ULOG_LOG_TYPE_NOTE,
ULOG_LOG_TYPE_SUCCESS
ULOG_LOG_TYPE_MESSAGE};
Different log types are prepended with different text and are displayed with different colours when logging to the terminal or imgui console widget.
Configuring the logger
To configure the logger, you can use the following functions:
setCrashOnErrors
- if set totrue
the application will terminate when an error is encounteredsetCurrentLogFile
- sets the current log file to the provided string location. This resets the file stream if one was previously open and opens a new file streamsetEnableLogging
- if set tofalse
calling any log function will not produce any outputsetLogOperation
- changes the log operation
There are 3 types of log operations, which are represented by the
LogOperations
enum:
enum LogOperations
{
,
ULOG_LOG_OPERATION_TERMINAL,
ULOG_LOG_OPERATION_FILE,
ULOG_LOG_OPERATION_FILE_AND_TERMINAL};
C API
The C API is really similar to the C++ API and looks like this:
void ULog_Logger_setCrashOnError(bool bError);
void ULog_Logger_setEnableLogging(bool bEnable);
void ULog_Logger_setCurrentLogFile(const char* file);
void ULog_Logger_setLogOperations(ULog_LogOperations op);
void ULog_Logger_log(ULog_LogType type, const char* fmt, ...);
void ULog_Logger_logV(ULog_LogType type, const char* fmt, va_list va_list);
The main differences are that namespaces and class names are
separated with _
due to the lack of support for namespaces
and classes in C and the 2 different versions of the
ULog_Logger_log
function.
In the C API, the ULog_Logger_log
function uses a format
string and a variadic arguments list. You can also use
ULog_Logger_logV
, which takes a va_list
instead of an ellipsis expression. More info on how the formatting
string should be structured can be found here.