Skip to content

Commit

Permalink
LOG: put all fields in the blackbox (added priority and tags)
Browse files Browse the repository at this point in the history
Fixes #36

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information
asalkeld committed May 28, 2012
1 parent ca9fbe0 commit d280ddd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
46 changes: 42 additions & 4 deletions lib/log_blackbox.c
Expand Up @@ -38,6 +38,8 @@ _blackbox_reload(int32_t target)
}

/* <u32> file lineno
* <u32> tags
* <u8> priority
* <u32> function name length
* <string> function name
* <u32> buffer length
Expand All @@ -51,6 +53,8 @@ _blackbox_vlogger(int32_t target,
size_t actual_size;
size_t fn_size;
char *chunk;
char *msg_len_pt;
uint32_t msg_len;
struct qb_log_target *t = qb_log_target_get(target);

if (t->instance == NULL) {
Expand All @@ -59,7 +63,7 @@ _blackbox_vlogger(int32_t target,

fn_size = strlen(cs->function) + 1;

actual_size = 2 * sizeof(uint32_t) + fn_size + sizeof(time_t);
actual_size = 4 * sizeof(uint32_t) + sizeof(uint8_t) + fn_size + sizeof(time_t);
max_size = actual_size + QB_LOG_MAX_LEN;

chunk = qb_rb_chunk_alloc(t->instance, max_size);
Expand All @@ -68,6 +72,14 @@ _blackbox_vlogger(int32_t target,
memcpy(chunk, &cs->lineno, sizeof(uint32_t));
chunk += sizeof(uint32_t);

/* tags */
memcpy(chunk, &cs->tags, sizeof(uint32_t));
chunk += sizeof(uint32_t);

/* log level/priority */
memcpy(chunk, &cs->priority, sizeof(uint8_t));
chunk += sizeof(uint8_t);

/* function name */
memcpy(chunk, &fn_size, sizeof(uint32_t));
chunk += sizeof(uint32_t);
Expand All @@ -78,8 +90,17 @@ _blackbox_vlogger(int32_t target,
memcpy(chunk, &timestamp, sizeof(time_t));
chunk += sizeof(time_t);

/* log message length */
msg_len_pt = chunk;
chunk += sizeof(uint32_t);

/* log message */
actual_size += qb_vsprintf_serialize(chunk, cs->format, ap);
msg_len = qb_vsprintf_serialize(chunk, cs->format, ap);
actual_size += msg_len;

/* now that we know the length, write it
*/
memcpy(msg_len_pt, &msg_len, sizeof(uint32_t));

(void)qb_rb_chunk_commit(t->instance, actual_size);
}
Expand Down Expand Up @@ -162,10 +183,13 @@ qb_log_blackbox_print_from_file(const char *bb_filename)
do {
char *ptr;
uint32_t lineno;
uint32_t tags;
uint8_t priority;
uint32_t fn_size;
char *function;
uint32_t len;
time_t timestamp;
uint32_t msg_len;
char message[QB_LOG_MAX_LEN];
uint32_t u32;

Expand All @@ -177,6 +201,14 @@ qb_log_blackbox_print_from_file(const char *bb_filename)
memcpy(&lineno, ptr, sizeof(uint32_t));
ptr += sizeof(uint32_t);

/* tags */
memcpy(&tags, ptr, sizeof(uint32_t));
ptr += sizeof(uint32_t);

/* priority */
memcpy(&priority, ptr, sizeof(uint8_t));
ptr += sizeof(uint8_t);

/* function size & name */
memcpy(&fn_size, ptr, sizeof(uint32_t));
ptr += sizeof(uint32_t);
Expand All @@ -197,15 +229,21 @@ qb_log_blackbox_print_from_file(const char *bb_filename)
snprintf(time_buf, sizeof(time_buf), "%ld",
(long int)timestamp);
}
/* message length */
memcpy(&msg_len, ptr, sizeof(uint32_t));
ptr += sizeof(uint32_t);

/* message content */
len = qb_vsnprintf_deserialize(message, QB_LOG_MAX_LEN, ptr);
len--;
while (message[len] == '\n' || message[len] == '\0') {
message[len] = '\0';
len--;
}
printf("%s %s(%d): %s\n",
time_buf, function, lineno, message);
message[msg_len] = '\0';
printf("%-7s %s %s(%u):%u: %s\n",
qb_log_priority2str(priority),
time_buf, function, lineno, tags, message);
}
} while (bytes_read > 0);
qb_rb_close(instance);
Expand Down
9 changes: 9 additions & 0 deletions lib/log_format.c
Expand Up @@ -114,6 +114,15 @@ qb_log_facility2str(int32_t fnum)
return NULL;
}

const char *
qb_log_priority2str(uint8_t priority)
{
if (priority > LOG_TRACE) {
return prioritynames[LOG_TRACE].c_name;
}
return prioritynames[priority].c_name;
}

void
qb_log_tags_stringify_fn_set(qb_log_tags_stringify_fn fn)
{
Expand Down
1 change: 1 addition & 0 deletions lib/log_int.h
Expand Up @@ -93,6 +93,7 @@ struct qb_log_callsite *qb_log_dcs_get(int32_t *newly_created,
uint32_t lineno,
uint32_t tags);

const char * qb_log_priority2str(uint8_t priority);
size_t qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap);
size_t qb_vsnprintf_deserialize(char *string, size_t str_len, const char *buf);

Expand Down

0 comments on commit d280ddd

Please sign in to comment.