This repository has been archived on 2026-05-29. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LightTAM/src/logger.c
T

80 lines
1.7 KiB
C

#include "logger.h"
Logger *initLogger(const char *_filename)
{
Logger *logger_struct = malloc(sizeof(Logger));
if (logger_struct == NULL)
{
return NULL;
}
logger_struct->f_log = fopen(_filename, "w");
if (logger_struct->f_log == NULL)
{
free(logger_struct);
return NULL;
}
pthread_mutex_init(&logger_struct->lock, NULL);
}
int logErrorEvent(Logger *_logger, const char *_message)
{
if (_logger == NULL)
{
return 0;
}
char current_time_str[32];
printDateAndTimeInString(time(NULL), current_time_str);
fprintf(_logger->f_log, "%s [ERROR] %s", current_time_str, _message);
return 1;
}
int logWarningEvent(Logger *_logger, const char *_message)
{
if (_logger == NULL)
{
return 0;
}
char current_time_str[32];
printDateAndTimeInString(time(NULL), current_time_str);
fprintf(_logger->f_log, "%s [WARNING] %s", current_time_str, _message);
return 1;
}
int logHardwareEvent(Logger *_logger, const char *_event_origin, const char *_message)
{
if (_logger == NULL)
{
return 0;
}
char current_time_str[32];
printDateAndTimeInString(time(NULL), current_time_str);
fprintf(_logger->f_log, "%s [%s] %s", current_time_str, _event_origin, _message);
return 1;
}
int logInfoEvent(Logger *_logger, const char *_message)
{
if (_logger == NULL)
{
return 0;
}
char current_time_str[32];
printDateAndTimeInString(time(NULL), current_time_str);
fprintf(_logger->f_log, "%s [INFO] %s", current_time_str, _message);
return 1;
}
int endLogger(Logger *_logger)
{
fclose(_logger->f_log);
free(_logger);
_logger = NULL;
return 0;
}