About
The logger interface allows to create new custom loggers for specific tasks and to access existing loggers. Loggers are presented in the "Console" window in Cinema 4D and registered at the maxon::Loggers registry.
Messages can be sent to the default logger using ApplicationOutput().
Custom Loggers
A new custom logger can be created with maxon::LoggerRef::Create() and is then registered at maxon::Loggers. A logger type defines the target of the logger (see Logger Types).
A custom logger is configured with:
const maxon::Id loggerID {
"net.maxonexample.logger" };
{
{
g_exampleLogger = maxon::Loggers::Default();
}
else
{
g_exampleLogger.SetName("Example Logger"_s);
maxon::Loggers::Insert(loggerID, g_exampleLogger)
iferr_return;
}
}
void SpecialEventAdd(Int32 messageid, UInt p1=0, UInt p2=0)
Definition: apibaseid.h:243
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:190
static auto Create(ARGS &&... args)
Definition: apibase.h:2818
#define iferr(...)
Definition: errorbase.h:388
const Class< R > & Get(const Id &cls)
Definition: objectbase.h:2073
#define iferr_return
Definition: resultbase.h:1524
static void FreeExampleLogger()
{
g_exampleLogger = nullptr;
}
#define MAXON_INITIALIZATION(...)
Definition: module.h:875
#define iferr_ignore(...)
Definition: resultbase.h:1489
Using Custom Loggers
A message is sent to a custom logger using the Write() function:
const maxon::Id loggerId {
"net.maxonexample.logger" };
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
Built-In Loggers
All existing loggers are registered at maxon::Loggers. These three loggers are there for public use:
- maxon::Loggers::Default: The default logger (published object for direct use).
- maxon::ID_LOGGER_PYTHON: The Python logger's ID, defined in python.framework, cpython.h.
- maxon::Loggers::Process: The IDE console logger (published object for direct use).
- Note
- The default logger is used with ApplicationOutput().
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
Logger Types
A logger type implements the actual processing of a given message e.g. if that message is displayed in the GUI or written to a file.
Logger types are based on maxon::LoggerTypeInterface:
for (const auto& loggerTypeAudience : logger.GetLoggerTypes())
{
const maxon::LoggerTypeRef loggerType = loggerTypeAudience.GetFirst();
loggerType.ObservableLoggerNotify(
true).AddObserver(LoggerCallback)
iferr_return;
}
maxon::UserLoggerTypeInterface is the logger type that displays the message in Cinema 4D's "Console" window:
maxon::FileLoggerTypeInterface is the logger type that writes the message to a file:
const maxon::LoggerRef defaultLogger = maxon::Loggers::Default();
for (const auto& logger : defaultLogger.GetLoggerTypes())
{
const maxon::LoggerTypeRef loggerType = logger.GetFirst();
if (loggerType.IsInstanceOf<maxon::UserLoggerTypeRef>())
{
const maxon::UserLoggerTypeRef userLoggerType = maxon::Cast<maxon::UserLoggerTypeRef>(loggerType);
{
}
}
return OK
Definition: apibase.h:2735
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:170
const char const char const char int line
Definition: object.h:440
Each object of LoggerLine represents an entry in the logger with several meta information....
Definition: logger.h:56
Further Reading