Skip to content

Commit

Permalink
lib: Move log type to be written before appended log prefix
Browse files Browse the repository at this point in the history
This changes the logging format back to how it used to be before the event
logging changes.
  • Loading branch information
sirainen authored and villesavolainen committed Sep 7, 2018
1 parent a50f086 commit d54d97c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/lib/event-log.c
Expand Up @@ -78,17 +78,20 @@ void e_debug(struct event *event,
}

static bool event_get_log_prefix(struct event *event, string_t *log_prefix,
bool *replace_prefix)
bool *replace_prefix, unsigned int *type_pos)
{
bool ret = FALSE;

if (event->log_prefix_replace) {
/* this event replaces all parent log prefixes */
*replace_prefix = TRUE;
*type_pos = event->log_prefix == NULL ? 0 :
strlen(event->log_prefix);
} else if (event->parent == NULL) {
/* append to default log prefix, don't replace it */
} else {
if (event_get_log_prefix(event->parent, log_prefix, replace_prefix))
if (event_get_log_prefix(event->parent, log_prefix,
replace_prefix, type_pos))
ret = TRUE;
}
if (event->log_prefix != NULL) {
Expand Down Expand Up @@ -156,6 +159,7 @@ event_logv_type(struct event *event, enum log_type log_type,
{
string_t *log_prefix_str = t_str_new(64);
bool replace_prefix = FALSE;
unsigned int type_pos = 0;

struct failure_context ctx = {
.type = log_type,
Expand All @@ -169,12 +173,14 @@ event_logv_type(struct event *event, enum log_type log_type,
event->source_linenum, &ctx))
abort_after_event = TRUE;

if (!event_get_log_prefix(event, log_prefix_str, &replace_prefix)) {
if (!event_get_log_prefix(event, log_prefix_str,
&replace_prefix, &type_pos)) {
/* keep log prefix as it is */
event_vsend(event, &ctx, fmt, args);
} else if (replace_prefix) {
/* event overrides the log prefix (even if it's "") */
ctx.log_prefix = str_c(log_prefix_str);
ctx.log_prefix_type_pos = type_pos;
event_vsend(event, &ctx, fmt, args);
} else {
/* append to log prefix, but don't fully replace it */
Expand Down
4 changes: 3 additions & 1 deletion src/lib/lib-event.h
Expand Up @@ -138,7 +138,9 @@ struct event *event_pop_global(struct event *event);
struct event *event_get_global(void);

/* Set the appended log prefix string for this event. All the parent events'
log prefixes will be concatenated together when logging. */
log prefixes will be concatenated together when logging. The log type
text (e.g. "Info: ") will be inserted before appended log prefixes (but
after replaced log prefix). */
struct event *
event_set_append_log_prefix(struct event *event, const char *prefix);
/* Replace the full log prefix string for this event. The parent events' log
Expand Down
12 changes: 6 additions & 6 deletions src/lib/test-event-log.c
Expand Up @@ -66,14 +66,14 @@ static void test_event_log_prefix(void)
},
.result = "replaced2.Info: TEXT",
},
/*{
{
.prefixes = (const struct test_log_prefix []) {
{ TYPE_REPLACE, "replaced1," },
{ TYPE_APPEND, "appended2." },
{ .type = TYPE_END }
},
.result = "replaced1,Info: appended2.TEXT",
},*/
},
{
.prefixes = (const struct test_log_prefix []) {
{ TYPE_APPEND, "appended1," },
Expand All @@ -99,15 +99,15 @@ static void test_event_log_prefix(void)
.global_log_prefix = "global3.",
.result = "global3.Info: appended1,appended2.TEXT",
},
/*{
{
.prefixes = (const struct test_log_prefix []) {
{ TYPE_APPEND, "appended1," },
{ TYPE_REPLACE, "replaced2." },
{ TYPE_APPEND, "appended3#" },
{ .type = TYPE_END }
},
.result = "replaced2.Info: appended3#TEXT",
},*/
},
{
.prefixes = (const struct test_log_prefix []) {
{ TYPE_APPEND, "appended1," },
Expand All @@ -118,7 +118,7 @@ static void test_event_log_prefix(void)
},
.result = "replaced4;Info: TEXT",
},
/*{
{
.prefixes = (const struct test_log_prefix []) {
{ TYPE_APPEND, "appended1," },
{ TYPE_REPLACE, "replaced2." },
Expand All @@ -128,7 +128,7 @@ static void test_event_log_prefix(void)
{ .type = TYPE_END }
},
.result = "replaced4;Info: appended5-TEXT",
},*/
},
};
const struct event_log_params params = {
.log_type = LOG_TYPE_INFO,
Expand Down

0 comments on commit d54d97c

Please sign in to comment.