[util] change the separator in derived loggers

This commit is contained in:
Milo Turner 2020-03-04 20:35:17 -05:00
parent c5b22a0175
commit 7d2c536d82
1 changed files with 5 additions and 4 deletions

View File

@ -5,6 +5,8 @@
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
static const char* const PREFIX_SEPARATOR = "/";
struct log_port; struct log_port;
struct log { struct log {
@ -51,8 +53,8 @@ struct log* log_derived(struct log* parent, const char* child_suffix)
return make_log( return make_log(
parent->derive_rgn, parent->derive_rgn,
rsprintf(parent->tmp_str_rgn, rsprintf(parent->tmp_str_rgn,
"%s::%s", "%s%s%s",
parent->prefix, child_suffix), parent->prefix, PREFIX_SEPARATOR, child_suffix),
parent->port); parent->port);
} }
@ -95,8 +97,7 @@ void log_writeln(struct log* lg, const char* str)
{ {
pthread_mutex_lock(&lg->port->mx); pthread_mutex_lock(&lg->port->mx);
if (lg->port->file) { if (lg->port->file) {
int pad = lg->port->padding - strlen(lg->prefix); fprintf(lg->port->file, "%*s | %s\n", (int) lg->port->padding, lg->prefix, str);
fprintf(lg->port->file, "%*s[%s] %s\n", pad, "", lg->prefix, str);
fflush(lg->port->file); fflush(lg->port->file);
} }
pthread_mutex_unlock(&lg->port->mx); pthread_mutex_unlock(&lg->port->mx);