httpdirfs/src/log.c

60 lines
1.4 KiB
C
Raw Normal View History

2021-08-22 01:51:37 +02:00
#include "log.h"
2021-08-22 03:26:09 +02:00
#include "config.h"
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-22 03:26:09 +02:00
char *env = getenv("HTTPDIRFS_LOG_LEVEL");
2021-08-22 01:51:37 +02:00
if (env) {
return atoi(env);
}
return DEFAULT_LOG_LEVEL;
}
2021-08-22 03:26:09 +02:00
int log_verbosity_init()
{
char *env = getenv("HTTPDIRFS_LOG_VERBOSITY");
if (env) {
return atoi(env);
}
return DEFAULT_LOG_VERBOSITY;
}
void log_printf(int type, const char *file, int line, const char *format, ...)
2021-08-22 01:51:37 +02:00
{
2021-08-22 03:26:09 +02:00
if (type & CONFIG.log_level) {
switch (type) {
case linfo:
2021-08-22 03:26:09 +02:00
goto print_actual_message;
break;
case lerror:
2021-08-22 03:26:09 +02:00
fprintf(stderr, "Error: ");
break;
case ldebug:
2021-08-22 03:26:09 +02:00
fprintf(stderr, "Debug: ");
break;
default:
fprintf(stderr, "Unknown (%x):", type);
break;
}
switch (CONFIG.log_verbosity) {
case LOG_SHOW_FILENAME:
fprintf(stderr, "(%s): ", file);
break;
case LOG_SHOW_FILENAME_LINE_NUM:
fprintf(stderr, "(%s:%d): ", file, line);
break;
}
print_actual_message:
/* A label can only be part of a statement, this is a statement. lol*/
{}
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
2021-08-22 01:51:37 +02:00
}