XLL+ Class Library (7.0)

Using the logging macros

You can find a full list of the logging macros here.

A logging macro takes two arguments. The first is a logger pointer, acquired as described in Directing log events.

The second argument is an expression which will be appended to the logger output streams. You can use any expression which can be used with std::ostream on the right-hand-side of a << operator. It can be a simple string, a number, or any object that supports the output stream operator. The expression may include any number of items, each separated by a << operator.

void MyClass:DoSomething()
    LOG_DEBUG(m_logger, "Starting some function");
    if (failed)
        LOG_FATAL(m_logger, "Fatal error condition. rc = " << rc);
    LOG_ERROR(m_logger, "Invalid option selected.");
    LOG_WARN(m_logger, "File " << strFileName << " contains errors and will be ignored.");
    LOG_INFO(m_logger, "Got user input. value = " << value << "; rc = " << rc);
    for (int i = 0; i < 1000; i++)
        LOG_TRACE(m_logger, "Some low-level info. " << i);

    LOG_DEBUG(m_logger, L"Use wide strings for Unicode builds.");
    LOG_FATAL(m_logger, _T("This will work under both Unicode and ANSI builds. rc = ") << rc);

Severity levels

The severity level of the log event is implied by the macro name. For a list of severity levels, in order of severity, see LogLevel.

What happens to the log events that you generate depends on how the logging framework has been configured. If your event is of sufficiently high severity, it will be written to all the appenders that are currently attached to the logger and its ancestors.


Strings must be in the appropriate format for the character set used by the build. If you are building in Unicode, the strings must be wide, e.g. std::wstring, L"My Unicode string". If the build uses MBCS, then you should use narrow strings, e.g. std::string, "My Unicode string".

You can avoid trouble by using the _T() macro for all literal strings, so that your code will build under either or both character sets.

Static destructors

The logging macros should not be used during the destructor of a statically declared object; if you do so, the results are unpredictable, and may cause Excel to crash.

Next: Configuring the logging framework >>