LoggerInterface/Inc/LoggerInterface.h

196 lines
9.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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"
#define MAX_COUNT_BUF_LOG 15
#define MAX_LEN_BUF_NAME_LOG 16
#define MAX_LEN_BUF_SMALL_LOG 32
#define MAX_LEN_BUF_BIG1_LOG 64
#define MAX_LEN_BUF_BIG2_LOG 192
typedef enum
{
LOG_BUF_SMALL,
LOG_BUF_BIG1,
LOG_BUF_BIG2
} LOG_BUF_TYPE;
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
);
typedef void (*LoggerGenericCanMethod)(
void *env,
uint16_t mChannel, /* номер канала */
uint8_t mFlags, /* бит 7 = RTR, остальные направление */
uint8_t mDLC, /* длина данных (0-8) */
uint32_t mID, /* идентификатор */
uint8_t *mData, /* данные */
uint32_t timestamp
);
typedef uint8_t * (*getMemPrintfBufLogMethod)(
void *env,
const char *authorStatic,
const uint8_t authorLen,
LOG_BUF_TYPE logBufType
);
extern tStringStatic LOGGER_LEVEL_NAMES[];
typedef struct {
void *env;
LoggerGenericMethod logging;
LoggerGenericCanMethod loggingCan;
getMemPrintfBufLogMethod getMemPrintfBufLog;
} 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