mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-30 16:13:51 +00:00
Support relative log.file config option
As already documented in doc/Servald-Configuration.md
This commit is contained in:
parent
dbd4cb1771
commit
546fccc794
@ -210,7 +210,7 @@ ATOM(char, vomp, 0, cf_opt_char_boolean,, "")
|
||||
END_STRUCT
|
||||
|
||||
STRUCT(log)
|
||||
STRING(256, file, "", cf_opt_absolute_path,, "Absolute path of log file")
|
||||
STRING(256, file, "", cf_opt_str_nonempty,, "Path of log file, either absolute or relative to instance directory")
|
||||
ATOM(int, show_pid, 1, cf_opt_int_boolean,, "If true, all log lines contain PID of logging process")
|
||||
ATOM(int, show_time, 1, cf_opt_int_boolean,, "If true, all log lines contain time stamp")
|
||||
END_STRUCT
|
||||
|
20
log.c
20
log.c
@ -79,15 +79,21 @@ static FILE *_open_logging()
|
||||
logpath = config.log.file;
|
||||
}
|
||||
if (!logpath || !logpath[0]) {
|
||||
logfile = stderr; //fopen("/tmp/foo", "a");
|
||||
logfile = stderr;
|
||||
INFO("No logfile configured -- logging to stderr");
|
||||
} else if ((logfile = fopen(logpath, "a"))) {
|
||||
setlinebuf(logfile);
|
||||
INFOF("Logging to %s (fd %d)", logpath, fileno(logfile));
|
||||
} else {
|
||||
logfile = stderr; //fopen("/tmp/bar", "a");
|
||||
WARNF_perror("fopen(%s)", logpath);
|
||||
WARNF("Cannot append to %s -- falling back to stderr", logpath);
|
||||
char path[1024];
|
||||
if (!FORM_SERVAL_INSTANCE_PATH(path, logpath)) {
|
||||
logfile = stderr;
|
||||
INFO("Logfile path overrun -- logging to stderr");
|
||||
} else if ((logfile = fopen(path, "a"))) {
|
||||
setlinebuf(logfile);
|
||||
INFOF("Logging to %s (fd %d)", path, fileno(logfile));
|
||||
} else {
|
||||
logfile = stderr;
|
||||
WARNF_perror("fopen(%s)", path);
|
||||
WARNF("Cannot append to %s -- falling back to stderr", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
return logfile;
|
||||
|
20
tests/config
20
tests/config
@ -264,4 +264,24 @@ test_InterfacesModernIncompatible() {
|
||||
--error-pattern='config file.*not loaded.*incompatible'
|
||||
}
|
||||
|
||||
doc_LogFileAbsolute="Absolute log file"
|
||||
test_LogFileAbsolute() {
|
||||
executeOk_servald config \
|
||||
set debug.verbose true \
|
||||
set log.file "$PWD/log"
|
||||
executeOk_servald echo one
|
||||
assertGrep log '^DEBUG:.*echo:argv\[1\]="one"$'
|
||||
assertGrep --matches=0 --message="log contains no error messages" log '^ERROR:'
|
||||
}
|
||||
|
||||
doc_LogFileRelative="Relative log file"
|
||||
test_LogFileRelative() {
|
||||
executeOk_servald config \
|
||||
set debug.verbose true \
|
||||
set log.file "log"
|
||||
executeOk_servald echo one
|
||||
assertGrep "$SERVALINSTANCE_PATH/log" '^DEBUG:.*echo:argv\[1\]="one"$'
|
||||
assertGrep --matches=0 --message="log contains no error messages" "$SERVALINSTANCE_PATH/log" '^ERROR:'
|
||||
}
|
||||
|
||||
runTests "$@"
|
||||
|
Loading…
x
Reference in New Issue
Block a user