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) {
|
2021-08-29 15:07:22 +02:00
|
|
|
case linfo:
|
2021-08-22 03:26:09 +02:00
|
|
|
goto print_actual_message;
|
|
|
|
break;
|
2021-08-29 15:07:22 +02:00
|
|
|
case lerror:
|
2021-08-22 03:26:09 +02:00
|
|
|
fprintf(stderr, "Error: ");
|
|
|
|
break;
|
2021-08-29 15:07:22 +02:00
|
|
|
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
|
|
|
}
|