implemented virtual logger
This commit is contained in:
26
include/tcp-chat/log.h
Normal file
26
include/tcp-chat/log.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include "tlibc/std.h"
|
||||
#include "tlibc/string/cstr.h"
|
||||
|
||||
typedef enum LogSeverity {
|
||||
LogSeverity_Debug,
|
||||
LogSeverity_Info,
|
||||
LogSeverity_Warn,
|
||||
LogSeverity_Error,
|
||||
} LogSeverity;
|
||||
|
||||
typedef void (*LogFunction_t)(void* logger, LogSeverity severity, cstr context, cstr msg);
|
||||
|
||||
#define log(severity, context, format, ...) { \
|
||||
if(LOG_FUNC) { \
|
||||
char* ___log_msg = sprintf_malloc(format ,##__VA_ARGS__); \
|
||||
LOG_FUNC(LOGGER, severity, context, ___log_msg); \
|
||||
free(___log_msg); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define logDebug(context, format, ...) log(LogSeverity_Debug, context, format ,##__VA_ARGS__)
|
||||
#define logInfo(context, format, ...) log(LogSeverity_Info, context, format ,##__VA_ARGS__)
|
||||
#define logWarn(context, format, ...) log(LogSeverity_Warn, context, format ,##__VA_ARGS__)
|
||||
#define logError(context, format, ...) log(LogSeverity_Error, context, format ,##__VA_ARGS__)
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
#include "tlibc/errors.h"
|
||||
#include "tlibc/string/str.h"
|
||||
#include "tcp-chat/log.h"
|
||||
|
||||
typedef struct Server Server;
|
||||
|
||||
Result(Server*) Server_createFromConfig(str config_str);
|
||||
Result(Server*) Server_create(str config_str, void* logger, LogFunction_t log_func);
|
||||
void Server_free(Server* server);
|
||||
Result(void) Server_run(Server* server);
|
||||
|
||||
Reference in New Issue
Block a user