httpd/httpd/src/logger/errors.c

50 lines
907 B
C
Raw Normal View History

#include "errors.h"
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include "../utils/time/fmt_time.h"
#include "logs.h"
// === Static variable
static struct logs_config config;
// === Functions
void errlog_init(bool enabled, FILE *logfile_stream)
{
config.enabled = enabled;
config.logfile_stream = logfile_stream;
}
void print_err()
{
print_log_err("%s", get_err());
}
void print_log_err(char *format, ...)
{
// Log prefix (time and server name)
fprintf(config.logfile_stream, "%s [%s] ", get_time(),
config.server_cfg->server_name);
// Print actual log
va_list args;
va_start(args, format);
vfprintf(config.logfile_stream, format, args);
va_end(args);
// New line
fprintf(config.logfile_stream, "\n");
// Print to stderr
fprintf(stderr, "Error: %s", get_err());
}
char *get_err()
{
return strerror(errno);
}