Начало

This commit is contained in:
cfif 2025-09-23 17:12:43 +03:00
commit 6fd64c63f1
4 changed files with 1421 additions and 0 deletions

160
Inc/LoggerInterface.h Normal file
View File

@ -0,0 +1,160 @@
//
// Created by xemon 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

25
Src/LoggerLevelNames.c Normal file
View File

@ -0,0 +1,25 @@
//
// Created by xemon on 13.11.22.
//
#include "LoggerInterface.h"
tStringStatic LOGGER_LEVEL_NAMES[] = {
StringStaticInit("FATAL"),
StringStaticInit("ERROR"),
StringStaticInit("WARN"),
StringStaticInit("INFO"),
StringStaticInit("DEBUG"),
StringStaticInit("TRACE"),
};
void LoggerInterfaceLogFormat(void *env,
char *authorStatic,
uint8_t authorLen,
eLoggerLevel loglevel,
char *msg,
uint16_t msgLen,
bool complete
) {
}

1219
Src/LoggerPrintf.c Normal file

File diff suppressed because it is too large Load Diff

17
modular.json Normal file
View File

@ -0,0 +1,17 @@
{
"dep": [
{
"type": "git",
"provider": "HVAC_DEV",
"repo": "BaseTypes"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}