161 lines
8.2 KiB
C
161 lines
8.2 KiB
C
//
|
|
// Created by CFIF on 13.11.22.
|
|
//
|
|
|
|
#ifndef UVEOS_ON_NATION_LOGGERINTERFACE_H
|
|
#define UVEOS_ON_NATION_LOGGERINTERFACE_H
|
|
|
|
#include <BaseTypes.h>
|
|
#include "stddef.h"
|
|
#include "stdint.h"
|
|
#include "stdbool.h"
|
|
|
|
typedef enum {
|
|
LOGLEVEL_FATAL,
|
|
LOGLEVEL_ERROR,
|
|
LOGLEVEL_WARN,
|
|
LOGLEVEL_INFO,
|
|
LOGLEVEL_DEBUG,
|
|
LOGLEVEL_TRACE,
|
|
} eLoggerLevel;
|
|
|
|
typedef void (*LoggerGenericMethod)(
|
|
void *env,
|
|
const char *authorStatic,
|
|
const uint8_t authorLen,
|
|
eLoggerLevel loglevel,
|
|
char *msg,
|
|
uint16_t msgLen,
|
|
bool complete
|
|
);
|
|
|
|
extern tStringStatic LOGGER_LEVEL_NAMES[];
|
|
|
|
typedef struct {
|
|
void *env;
|
|
LoggerGenericMethod logging;
|
|
} tLoggerInterface;
|
|
|
|
|
|
void LoggerPrintf(
|
|
tLoggerInterface *logger,
|
|
const char *authorStatic,
|
|
const uint8_t authorLen,
|
|
eLoggerLevel loglevel,
|
|
bool complete,
|
|
const char *fmt,
|
|
...
|
|
);
|
|
|
|
#ifndef LOGGER_LEVEL_INFO
|
|
|
|
#define LOGGER_LEVEL_INFO 1
|
|
|
|
#endif
|
|
|
|
#ifndef LOGGER_LEVEL_TRACE
|
|
|
|
#define LOGGER_LEVEL_TRACE 0
|
|
|
|
#endif
|
|
|
|
#ifndef LOGGER_LEVEL_ERROR
|
|
|
|
#define LOGGER_LEVEL_ERROR 1
|
|
|
|
#endif
|
|
|
|
#define LoggerFormat
|
|
|
|
#if LOGGER_LEVEL_ERROR
|
|
#define LoggerErrorStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR, MSG, sizeof(MSG)-1,true); }
|
|
#define LoggerCnErrorStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR, MSG, sizeof(MSG)-1,false); }
|
|
#define LoggerError(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR, MSG, SIZE,true); }
|
|
#define LoggerCnError(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR, MSG, SIZE,false); }
|
|
#define LoggerFormatError(LOGGER, AUTHOR, FMT_MSG, ...) if(LOGGER){ LoggerPrintf(LOGGER,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR,true, FMT_MSG, __VA_ARGS__); }
|
|
|
|
#define LoggerErrorStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR, MSG, sizeof(MSG)-1,true); }
|
|
#define LoggerCnErrorStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR, MSG, sizeof(MSG)-1,false); }
|
|
#define LoggerError(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR, MSG, SIZE,true); }
|
|
#define LoggerCnError(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR, MSG, SIZE,false); }
|
|
#define LoggerFormatError(LOGGER, AUTHOR, FMT_MSG, ...) if(LOGGER){ LoggerPrintf(LOGGER,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_ERROR,true, FMT_MSG, __VA_ARGS__); }
|
|
|
|
#else
|
|
#define LoggerStrErrorStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerStrCnErrorStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerStrError(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerStrCnError(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerStrFormatError(LOGGER, AUTHOR, FMT_MSG, ...) // невыводим
|
|
|
|
|
|
#define LoggerStrErrorStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerStrCnErrorStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerStrError(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerStrCnError(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerStrFormatError(LOGGER, AUTHOR, FMT_MSG, ...) // невыводим
|
|
|
|
#endif
|
|
|
|
#if LOGGER_LEVEL_INFO
|
|
#define LoggerInfoRaw(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_INFO, MSG, SIZE, true); }
|
|
|
|
#define LoggerInfoStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_INFO, MSG, sizeof(MSG)-1,true); }
|
|
#define LoggerCnInfoStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_INFO, MSG, sizeof(MSG)-1,false); }
|
|
#define LoggerInfo(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_INFO, MSG, SIZE,true); }
|
|
#define LoggerCnInfo(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_INFO, MSG, SIZE,false); }
|
|
#define LoggerFormatInfo(LOGGER, AUTHOR, FMT_MSG, ...) if(LOGGER){ LoggerPrintf(LOGGER,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_INFO,true, FMT_MSG, __VA_ARGS__); }
|
|
|
|
|
|
#define LoggerStrInfoStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,strlen(AUTHOR),LOGLEVEL_INFO, MSG, sizeof(MSG)-1,true); }
|
|
#define LoggerStrCnInfoStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,strlen(AUTHOR),LOGLEVEL_INFO, MSG, sizeof(MSG)-1,false); }
|
|
#define LoggerStrInfo(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,strlen(AUTHOR),LOGLEVEL_INFO, MSG, SIZE,true); }
|
|
#define LoggerStrCnInfo(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,strlen(AUTHOR),LOGLEVEL_INFO, MSG, SIZE,false); }
|
|
#define LoggerStrFormatInfo(LOGGER, AUTHOR, FMT_MSG, ...) if(LOGGER){ LoggerPrintf(LOGGER,AUTHOR,strlen(AUTHOR),LOGLEVEL_INFO,true, FMT_MSG, __VA_ARGS__); }
|
|
|
|
#else
|
|
#define LoggerInfoStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerCnInfoStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerInfo(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerCnInfo(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerFormatInfo(LOGGER, AUTHOR, FMT_MSG, ...) // невыводим
|
|
|
|
#define LoggerStrInfoStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerStrCnInfoStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerStrInfo(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerStrCnInfo(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerStrFormatInfo(LOGGER, AUTHOR, FMT_MSG, ...) // невыводим
|
|
|
|
#endif
|
|
|
|
|
|
#if LOGGER_LEVEL_TRACE
|
|
#define LoggerCnTraceStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE, MSG, sizeof(MSG)-1,false); }
|
|
#define LoggerTraceStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE, MSG, sizeof(MSG)-1,true); }
|
|
#define LoggerTrace(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE, MSG, SIZE,true); }
|
|
#define LoggerCnTrace(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE, MSG, SIZE,false); }
|
|
#define LoggerFormatTrace(LOGGER, AUTHOR, FMT_MSG, ...) if(LOGGER){ LoggerPrintf(LOGGER,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE,true, FMT_MSG, __VA_ARGS__); }
|
|
|
|
#define LoggerStrCnTraceStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE, MSG, sizeof(MSG)-1,false); }
|
|
#define LoggerStrTraceStatic(LOGGER, AUTHOR, MSG) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE, MSG, sizeof(MSG)-1,true); }
|
|
#define LoggerStrTrace(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE, MSG, SIZE,true); }
|
|
#define LoggerStrCnTrace(LOGGER, AUTHOR, MSG, SIZE) if(LOGGER){ (LOGGER)->logging((LOGGER)->env,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE, MSG, SIZE,false); }
|
|
#define LoggerStrFormatTrace(LOGGER, AUTHOR, FMT_MSG, ...) if(LOGGER){ LoggerPrintf(LOGGER,AUTHOR,sizeof(AUTHOR)-1,LOGLEVEL_TRACE,true, FMT_MSG, __VA_ARGS__); }
|
|
|
|
#else
|
|
#define LoggerCnTraceStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerTraceStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerTrace(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerCnTrace(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerFormatTrace(LOGGER, AUTHOR, FMT_MSG, ...) // невыводим
|
|
|
|
|
|
#define LoggerStrCnTraceStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerStrTraceStatic(LOGGER, AUTHOR, MSG) // невыводим
|
|
#define LoggerStrTrace(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerStrCnTrace(LOGGER, AUTHOR, MSG, SIZE) // невыводим
|
|
#define LoggerStrFormatTrace(LOGGER, AUTHOR, FMT_MSG, ...) // невыводим
|
|
|
|
#endif
|
|
|
|
#endif //UVEOS_ON_NATION_LOGGERINTERFACE_H
|