Skip to content

Commit

Permalink
logging: Add option to suppress timestamp printing in log_output
Browse files Browse the repository at this point in the history
Added flag in log_output module to add timestamp when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
  • Loading branch information
nordic-krch authored and carlescufi committed Sep 26, 2018
1 parent 07da32a commit 2cc6d0c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
9 changes: 6 additions & 3 deletions include/logging/log_output.h
Expand Up @@ -22,13 +22,16 @@ extern "C" {
/** @brief Flag forcing ANSI escape code colors, red (errors), yellow
* (warnings).
*/
#define LOG_OUTPUT_FLAG_COLORS (1 << 0)
#define LOG_OUTPUT_FLAG_COLORS BIT(0)

/** @brief Flag forcing timestamp */
#define LOG_OUTPUT_FLAG_TIMESTAMP BIT(1)

/** @brief Flag forcing timestamp formatting. */
#define LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP (1 << 1)
#define LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP BIT(2)

/** @brief Flag forcing severity level prefix. */
#define LOG_OUTPUT_FLAG_LEVEL (1 << 2)
#define LOG_OUTPUT_FLAG_LEVEL BIT(3)

/**
* @brief Prototype of the function processing output data.
Expand Down
2 changes: 1 addition & 1 deletion subsys/logging/log_backend_native_posix.c
Expand Up @@ -61,7 +61,7 @@ static void put(const struct log_backend *const backend,
{
log_msg_get(msg);

u32_t flags = LOG_OUTPUT_FLAG_LEVEL;
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;

if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
if (posix_trace_over_tty(0)) {
Expand Down
2 changes: 1 addition & 1 deletion subsys/logging/log_backend_uart.c
Expand Up @@ -32,7 +32,7 @@ static void put(const struct log_backend *const backend,
{
log_msg_get(msg);

u32_t flags = LOG_OUTPUT_FLAG_LEVEL;
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;

if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
flags |= LOG_OUTPUT_FLAG_COLORS;
Expand Down
11 changes: 9 additions & 2 deletions subsys/logging/log_output.c
Expand Up @@ -364,11 +364,18 @@ static int prefix_print(struct log_msg *msg,
int length = 0;

if (!log_msg_is_raw_string(msg)) {
bool stamp_format = flags & LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
bool stamp = flags & LOG_OUTPUT_FLAG_TIMESTAMP;
bool colors_on = flags & LOG_OUTPUT_FLAG_COLORS;
bool level_on = flags & LOG_OUTPUT_FLAG_LEVEL;

length += timestamp_print(msg, log_output, stamp_format);
if (stamp) {
bool stamp_format =
flags & LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;

length += timestamp_print(msg, log_output,
stamp_format);
}

color_prefix(msg, log_output, colors_on);
length += ids_print(msg, log_output, level_on);
}
Expand Down
4 changes: 3 additions & 1 deletion subsys/shell/shell_log_backend.c
Expand Up @@ -74,7 +74,9 @@ void shell_log_backend_disable(const struct shell_log_backend *backend)
static void msg_process(const struct log_output *log_output,
struct log_msg *msg)
{
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
u32_t flags = LOG_OUTPUT_FLAG_LEVEL |
LOG_OUTPUT_FLAG_TIMESTAMP |
LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;

if (IS_ENABLED(CONFIG_SHELL_VT100_COLORS)) {
flags |= LOG_OUTPUT_FLAG_COLORS;
Expand Down

0 comments on commit 2cc6d0c

Please sign in to comment.