Program Listing for File log.h

Return to documentation for file (include/libcaer/log.h)

#ifndef LIBCAER_LOG_H_
#define LIBCAER_LOG_H_

#ifdef __cplusplus

#   include <cstdarg>
#   include <cstdint>
#   include <cstddef>

#else

#   include <stdarg.h>
#   include <stdint.h>
#   include <stddef.h>

#endif

// printf() like formatting checks.
#if defined(__GNUC__) || defined(__clang__)
#   if defined(__USE_MINGW_ANSI_STDIO)
#       define ATTRIBUTE_FORMAT(N)    __attribute__((format(gnu_printf, N, (N + 1))))
#       define ATTRIBUTE_FORMAT_VA(N) __attribute__((format(gnu_printf, N, 0)))
#   else
#       define ATTRIBUTE_FORMAT(N)    __attribute__((format(printf, N, (N + 1))))
#       define ATTRIBUTE_FORMAT_VA(N) __attribute__((format(printf, N, 0)))
#   endif
#else
#   define ATTRIBUTE_FORMAT(N)
#   define ATTRIBUTE_FORMAT_VA(N)
#endif

// Shared objects visibility (DLL/SO).
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#   ifdef __GNUC__
#       define LIBRARY_PUBLIC_VISIBILITY __attribute__((dllexport)) __attribute__((cdecl))
#   else
#       define LIBRARY_PUBLIC_VISIBILITY __declspec(dllexport)
#   endif
#else
#   define LIBRARY_PUBLIC_VISIBILITY __attribute__((visibility("default")))
#endif

#ifdef __cplusplus
extern "C" {
#endif

enum caer_log_level {
    CAER_LOG_EMERGENCY = 0,
    CAER_LOG_ALERT     = 1,
    CAER_LOG_CRITICAL  = 2,
    CAER_LOG_ERROR     = 3,
    CAER_LOG_WARNING   = 4,
    CAER_LOG_NOTICE    = 5,
    CAER_LOG_INFO      = 6,
    CAER_LOG_DEBUG     = 7,
};

LIBRARY_PUBLIC_VISIBILITY void caerLogLevelSet(enum caer_log_level logLevel);

LIBRARY_PUBLIC_VISIBILITY enum caer_log_level caerLogLevelGet(void);

typedef void (*caerLogCallback)(const char *msg, size_t msgLength);

LIBRARY_PUBLIC_VISIBILITY void caerLogCallbackSet(caerLogCallback callback);

LIBRARY_PUBLIC_VISIBILITY caerLogCallback caerLogCallbackGet(void);

LIBRARY_PUBLIC_VISIBILITY void caerLogFileDescriptorsSet(int fd1, int fd2);

LIBRARY_PUBLIC_VISIBILITY int caerLogFileDescriptorsGetFirst(void);

LIBRARY_PUBLIC_VISIBILITY int caerLogFileDescriptorsGetSecond(void);

LIBRARY_PUBLIC_VISIBILITY void caerLogDisable(bool disableLogging);

LIBRARY_PUBLIC_VISIBILITY bool caerLogDisabled(void);

LIBRARY_PUBLIC_VISIBILITY void caerLog(enum caer_log_level logLevel, const char *subSystem, const char *format, ...)
    ATTRIBUTE_FORMAT(3);

LIBRARY_PUBLIC_VISIBILITY void caerLogVA(
    enum caer_log_level logLevel, const char *subSystem, const char *format, va_list args) ATTRIBUTE_FORMAT_VA(3);

LIBRARY_PUBLIC_VISIBILITY void caerLogVAFull(uint8_t systemLogLevel, enum caer_log_level logLevel,
    const char *subSystem, const char *format, va_list args) ATTRIBUTE_FORMAT_VA(4);

#ifdef __cplusplus
}
#endif

#endif /* LIBCAER_LOG_H_ */