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-31 15:00:47 +02:00
|
|
|
#include <curl/curl.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-31 12:18:39 +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,
|
2021-08-31 12:15:00 +02:00
|
|
|
const char *format, ...)
|
2021-08-22 01:51:37 +02:00
|
|
|
{
|
2021-08-31 12:18:39 +02:00
|
|
|
if (type & CONFIG.log_type) {
|
|
|
|
switch (type) {
|
|
|
|
case fatal:
|
2021-08-31 13:23:43 +02:00
|
|
|
fprintf(stderr, "Fatal:");
|
2021-08-31 12:18:39 +02:00
|
|
|
break;
|
|
|
|
case error:
|
2021-08-31 13:23:43 +02:00
|
|
|
fprintf(stderr, "Error:");
|
2021-08-31 12:18:39 +02:00
|
|
|
break;
|
|
|
|
case warning:
|
2021-08-31 13:23:43 +02:00
|
|
|
fprintf(stderr, "Warning:");
|
2021-08-31 12:18:39 +02:00
|
|
|
break;
|
|
|
|
case info:
|
|
|
|
goto print_actual_message;
|
|
|
|
default:
|
2021-08-31 13:23:43 +02:00
|
|
|
fprintf(stderr, "Debug(%x):", type);
|
2021-08-31 12:18:39 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-08-29 23:46:24 +02:00
|
|
|
|
2021-08-31 13:23:43 +02:00
|
|
|
fprintf(stderr, "%s:%d:", file, line);
|
2021-08-29 23:46:24 +02:00
|
|
|
|
2021-09-03 15:56:11 +02:00
|
|
|
print_actual_message: {
|
2021-08-31 12:18:39 +02:00
|
|
|
}
|
2021-08-31 19:49:49 +02:00
|
|
|
fprintf(stderr, "%s: ", func);
|
2021-08-31 12:18:39 +02:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2021-08-31 13:23:43 +02:00
|
|
|
vfprintf(stderr, format, args);
|
2021-08-31 12:18:39 +02:00
|
|
|
va_end(args);
|
2021-08-30 03:50:03 +02:00
|
|
|
|
2021-08-31 12:18:39 +02:00
|
|
|
if (type == fatal) {
|
|
|
|
exit_failure();
|
2021-08-31 12:15:00 +02:00
|
|
|
}
|
2021-08-31 12:18:39 +02:00
|
|
|
}
|
2021-08-31 15:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_version()
|
|
|
|
{
|
|
|
|
/* FUSE prints its help to stderr */
|
2022-04-23 03:49:16 +02:00
|
|
|
fprintf(stderr, "HTTPDirFS version " VERSION "\n");
|
2021-08-31 15:00:47 +02:00
|
|
|
/*
|
|
|
|
* --------- Print off SSL engine version ---------
|
|
|
|
*/
|
|
|
|
curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
|
2022-04-23 03:49:16 +02:00
|
|
|
fprintf(stderr, "libcurl SSL engine: %s\n", data->ssl_version);
|
2021-08-31 19:49:49 +02:00
|
|
|
}
|