Difference between revisions of "Writing to the Event Log"

From The Foundry MODO SDK wiki
Jump to: navigation, search
(Created page with "Status of the running plug-in can be written to the event log, either for the user or for the developer to examine debug state. ==== CLxLogMessage ==== This utility class is th...")
(No difference)

Revision as of 00:01, 15 February 2012

Status of the running plug-in can be written to the event log, either for the user or for the developer to examine debug state.

CLxLogMessage

This utility class is the easiest way to write to the log, although it was designed for file I/O and still has some of that legacy. You need to declare your own sub-class which implements the Format() and Version() methods for your plug-in.

class CMyLogMessage : public CLxLogMessage
{
    public:
        const char * GetFormat ()
        {
                return "My Format";
        }

        const char * GetVersion ()
        {
                return "My Version";
        }
};

Declare your class as a persistent object somewhere, and you can then output info and errors to the event log.

        CMyLogMessage        my_log;
        ...

        my_log.Error ("Help! Something scary!");
        my_log.Info ("Nevermind -- just my own shadow");

These messages will be tagged with your format and version. If you don't care for that you can compose messages more directly. It's also possible to append sub-messages in the log, which will be appear as collapsible sub-items in the event log viewport.

        my_log.Message ("CMyPlug", "MyMethod", "Multiple values already set:");
        my_log.SubMessage (0, 0, "Value 1");
        my_log.SubMessage (0, 0, "Value 2");

Custom Logs

By default the CLxLogMessage implementation writes to the "io-status" event log. That can be overwritten in the constructor:

class CMyLogMessage : public CLxLogMessage
{
    public:
        CMyLogMessage() : CLxLogMessage ("myLog") {}
        ...

The name can be any existing log, but if the log doesn't otherwise exist it has to be declared by the server. This can be done by adding the name(s) of logs that the server wants to use to the server's tags.

   { LXsSRV_LOGSUBSYSTEM,  "myLog" },