2021-08-22 01:51:37 +02:00
|
|
|
#include "log.h"
|
|
|
|
|
2021-08-22 03:26:09 +02:00
|
|
|
#include "config.h"
|
2021-08-30 03:50:03 +02:00
|
|
|
#include "util.h"
|
2021-08-22 03:26:09 +02:00
|
|
|
|
2021-08-22 01:51:37 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2021-08-22 03:26:09 +02:00
|
|
|
#include <stdlib.h>
|
2021-08-22 01:51:37 +02:00
|
|
|
|
2021-08-22 03:26:09 +02:00
|
|
|
int log_level_init()
|
2021-08-22 01:51:37 +02:00
|
|
|
{
|
2021-08-30 12:24:32 +02:00
|
|
|
char *env = getenv("HTTPDIRFS_LOG_LEVEL");
|
|
|
|
if (env) {
|
|
|
|
return atoi(env);
|
|
|
|
}
|
|
|
|
return DEFAULT_LOG_LEVEL;
|
2021-08-22 01:51:37 +02:00
|
|
|
}
|
|
|
|
|
2021-08-30 12:24:32 +02:00
|
|
|
void
|
|
|
|
log_printf(LogType type, const char *file, const char *func, int line,
|
|
|
|
const char *format, ...)
|
2021-08-22 01:51:37 +02:00
|
|
|
{
|
2021-08-30 12:24:32 +02:00
|
|
|
FILE *out = stderr;
|
|
|
|
if (type & CONFIG.log_type) {
|
|
|
|
switch (type) {
|
|
|
|
case fatal:
|
|
|
|
fprintf(out, "Fatal: ");
|
|
|
|
break;
|
|
|
|
case error:
|
|
|
|
fprintf(out, "Error: ");
|
|
|
|
break;
|
|
|
|
case warning:
|
|
|
|
fprintf(out, "Warning: ");
|
|
|
|
break;
|
|
|
|
case info:
|
|
|
|
out = stdout;
|
|
|
|
goto print_actual_message;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(out, "Debug (%x):", type);
|
|
|
|
break;
|
|
|
|
}
|
2021-08-29 23:46:24 +02:00
|
|
|
|
2021-08-30 12:24:32 +02:00
|
|
|
fprintf(out, "(%s:%s:%d): ", file, func, line);
|
2021-08-29 23:46:24 +02:00
|
|
|
|
2021-08-30 12:24:32 +02:00
|
|
|
print_actual_message:
|
|
|
|
{
|
|
|
|
}
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(out, format, args);
|
|
|
|
va_end(args);
|
2021-08-30 03:50:03 +02:00
|
|
|
|
2021-08-30 12:24:32 +02:00
|
|
|
if (type == fatal) {
|
|
|
|
exit_failure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|