LogWrite

Table of Contents

LogWrite

Description

Core log message generation function

Parameters

NameDirectionDescription
typeinSeverity level of message
taginSource identifier (typically function name)
lineinSource line number
msginConstant string to be printed

Success

Message formatted and written to log output

Failure

Message silently dropped (output not guaranteed)

Usage example (Cross-references)

    }
    
    void LogWrite(LogMessageType type, const char *tag, int line, const char *msg) {
    if (!msg) {
    return;
    Str m_ = StrInit();                                                                                            \
    StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
    LogWrite(LOG_MESSAGE_TYPE_FATAL, __func__, __LINE__, m_.data);                                                 \
    StrDeinit(&m_);                                                                                                \
    SysAbort();                                                                                                    \
    Str m_ = StrInit();                                                                                            \
    StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
    LogWrite(LOG_MESSAGE_TYPE_ERROR, __func__, __LINE__, m_.data);                                                 \
    StrDeinit(&m_);                                                                                                \
    } while (0)
    Str m_ = StrInit();                                                                                            \
    StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
    LogWrite(LOG_MESSAGE_TYPE_INFO, __func__, __LINE__, m_.data);                                                  \
    StrDeinit(&m_);                                                                                                \
    } while (0)
    StrWriteFmt(&m_, " : {}", syserr_);                                                                        \
    });                                                                                                            \
    LogWrite(LOG_MESSAGE_TYPE_FATAL, __func__, __LINE__, m_.data);                                                 \
    StrDeinit(&m_);                                                                                                \
    SysAbort();                                                                                                    \
    StrWriteFmt(&m_, " : {}", syserr_);                                                                        \
    });                                                                                                            \
    LogWrite(LOG_MESSAGE_TYPE_ERROR, __func__, __LINE__, m_.data);                                                 \
    StrDeinit(&m_);                                                                                                \
    } while (0)
    StrWriteFmt(&m_, " : {}", syserr_);                                                                        \
    });                                                                                                            \
    LogWrite(LOG_MESSAGE_TYPE_INFO, __func__, __LINE__, m_.data);                                                  \
    StrDeinit(&m_);                                                                                                \
    } while (0)

Share :

Related Posts

SysSetAbortCallback

SysSetAbortCallback Description Set a custom callback function for SysAbort. If no callback is set, SysAbort will call the standard abort() function.

Read More

SysAbort

SysAbort Description Custom abort function that can be redirected for testing purposes. By default, this calls the standard abort() function. If a callback is set via SysSetAbortCallback, it calls the callback instead.

Read More

LOG_ERROR

LOG_ERROR Description Writes an error-level log message. …[in] : Format string and arguments following printf-style syntax.

Read More