mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
Unify log_to_file(...) and log_default_print(...)
This commit is contained in:
parent
ebef98d8be
commit
2c03be11b6
@ -49,23 +49,32 @@ struct log {
|
||||
const char *prefix;
|
||||
};
|
||||
|
||||
static void log_to_file(const char *prefix,
|
||||
enum log_level level,
|
||||
bool continued,
|
||||
const struct timeabs *time,
|
||||
const char *str,
|
||||
FILE *logf)
|
||||
{
|
||||
char iso8601_msec_fmt[sizeof("YYYY-mm-ddTHH:MM:SS.%03dZ")];
|
||||
strftime(iso8601_msec_fmt, sizeof(iso8601_msec_fmt), "%FT%T.%%03dZ", gmtime(&time->ts.tv_sec));
|
||||
char iso8601_s[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ")];
|
||||
snprintf(iso8601_s, sizeof(iso8601_s), iso8601_msec_fmt, (int) time->ts.tv_nsec / 1000000);
|
||||
if (!continued) {
|
||||
fprintf(logf, "%s %s %s\n", iso8601_s, prefix, str);
|
||||
} else {
|
||||
fprintf(logf, "%s %s \t%s\n", iso8601_s, prefix, str);
|
||||
}
|
||||
fflush(logf);
|
||||
}
|
||||
|
||||
static void log_default_print(const char *prefix,
|
||||
enum log_level level,
|
||||
bool continued,
|
||||
const struct timeabs *time,
|
||||
const char *str, void *arg)
|
||||
{
|
||||
char iso8601_msec_fmt[sizeof("YYYY-mm-ddTHH:MM:SS.%03dZ")];
|
||||
strftime(iso8601_msec_fmt, sizeof(iso8601_msec_fmt), "%FT%T.%%03dZ", gmtime(&time->ts.tv_sec));
|
||||
char iso8601_s[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ")];
|
||||
snprintf(iso8601_s, sizeof(iso8601_s), iso8601_msec_fmt, (int) time->ts.tv_nsec / 1000000);
|
||||
|
||||
if (!continued) {
|
||||
printf("%s %s %s\n", iso8601_s, prefix, str);
|
||||
} else {
|
||||
printf("%s %s \t%s\n", iso8601_s, prefix, str);
|
||||
}
|
||||
fflush(stdout);
|
||||
log_to_file(prefix, level, continued, time, str, stdout);
|
||||
}
|
||||
|
||||
static size_t log_bufsize(const struct log_entry *e)
|
||||
@ -408,21 +417,6 @@ static void show_log_prefix(char buf[OPT_SHOW_LEN], const struct log *log)
|
||||
strncpy(buf, log->prefix, OPT_SHOW_LEN);
|
||||
}
|
||||
|
||||
static void log_to_file(const char *prefix,
|
||||
enum log_level level,
|
||||
bool continued,
|
||||
const struct timeabs *time,
|
||||
const char *str,
|
||||
FILE *logf)
|
||||
{
|
||||
if (!continued) {
|
||||
fprintf(logf, "%s %s\n", prefix, str);
|
||||
} else {
|
||||
fprintf(logf, "%s \t%s\n", prefix, str);
|
||||
}
|
||||
fflush(logf);
|
||||
}
|
||||
|
||||
char *arg_log_to_file(const char *arg, struct lightningd *ld)
|
||||
{
|
||||
FILE *logf;
|
||||
|
Loading…
Reference in New Issue
Block a user