logging : do not reuse tag name log_output
Do not reuse tag name (misra rule 5.7). Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
0ac3073d20
commit
2976e12946
3 changed files with 132 additions and 133 deletions
|
@ -45,12 +45,12 @@ static const char *const colors[] = {
|
|||
static uint32_t freq;
|
||||
static uint32_t timestamp_div;
|
||||
|
||||
extern void log_output_msg_syst_process(const struct log_output *log_output,
|
||||
extern void log_output_msg_syst_process(const struct log_output *output,
|
||||
struct log_msg *msg, uint32_t flag);
|
||||
extern void log_output_string_syst_process(const struct log_output *log_output,
|
||||
extern void log_output_string_syst_process(const struct log_output *output,
|
||||
struct log_msg_ids src_level,
|
||||
const char *fmt, va_list ap, uint32_t flag);
|
||||
extern void log_output_hexdump_syst_process(const struct log_output *log_output,
|
||||
extern void log_output_hexdump_syst_process(const struct log_output *output,
|
||||
struct log_msg_ids src_level,
|
||||
const uint8_t *data, uint32_t length, uint32_t flag);
|
||||
|
||||
|
@ -96,8 +96,7 @@ static int level_to_rfc5424_severity(uint32_t level)
|
|||
|
||||
static int out_func(int c, void *ctx)
|
||||
{
|
||||
const struct log_output *out_ctx =
|
||||
(const struct log_output *)ctx;
|
||||
const struct log_output *out_ctx = (const struct log_output *)ctx;
|
||||
int idx;
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
||||
|
@ -118,14 +117,14 @@ static int out_func(int c, void *ctx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int print_formatted(const struct log_output *log_output,
|
||||
static int print_formatted(const struct log_output *output,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int length = 0;
|
||||
|
||||
va_start(args, fmt);
|
||||
length = cbvprintf(out_func, (void *)log_output, fmt, args);
|
||||
length = cbvprintf(out_func, (void *)output, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return length;
|
||||
|
@ -144,16 +143,16 @@ static void buffer_write(log_output_func_t outf, uint8_t *buf, size_t len,
|
|||
}
|
||||
|
||||
|
||||
void log_output_flush(const struct log_output *log_output)
|
||||
void log_output_flush(const struct log_output *output)
|
||||
{
|
||||
buffer_write(log_output->func, log_output->buf,
|
||||
log_output->control_block->offset,
|
||||
log_output->control_block->ctx);
|
||||
buffer_write(output->func, output->buf,
|
||||
output->control_block->offset,
|
||||
output->control_block->ctx);
|
||||
|
||||
log_output->control_block->offset = 0;
|
||||
output->control_block->offset = 0;
|
||||
}
|
||||
|
||||
static int timestamp_print(const struct log_output *log_output,
|
||||
static int timestamp_print(const struct log_output *output,
|
||||
uint32_t flags, uint32_t timestamp)
|
||||
{
|
||||
int length;
|
||||
|
@ -163,7 +162,7 @@ static int timestamp_print(const struct log_output *log_output,
|
|||
|
||||
|
||||
if (!format) {
|
||||
length = print_formatted(log_output, "[%08lu] ", timestamp);
|
||||
length = print_formatted(output, "[%08lu] ", timestamp);
|
||||
} else if (freq != 0U) {
|
||||
uint32_t total_seconds;
|
||||
uint32_t remainder;
|
||||
|
@ -197,15 +196,15 @@ static int timestamp_print(const struct log_output *log_output,
|
|||
|
||||
strftime(time_str, sizeof(time_str), "%FT%T", tm);
|
||||
|
||||
length = print_formatted(log_output, "%s.%06dZ ",
|
||||
length = print_formatted(output, "%s.%06dZ ",
|
||||
time_str, ms * 1000U + us);
|
||||
#else
|
||||
length = print_formatted(log_output,
|
||||
length = print_formatted(output,
|
||||
"1970-01-01T%02d:%02d:%02d.%06dZ ",
|
||||
hours, mins, seconds, ms * 1000U + us);
|
||||
#endif
|
||||
} else {
|
||||
length = print_formatted(log_output,
|
||||
length = print_formatted(output,
|
||||
"[%02d:%02d:%02d.%03d,%03d] ",
|
||||
hours, mins, seconds, ms, us);
|
||||
}
|
||||
|
@ -216,39 +215,39 @@ static int timestamp_print(const struct log_output *log_output,
|
|||
return length;
|
||||
}
|
||||
|
||||
static void color_print(const struct log_output *log_output,
|
||||
static void color_print(const struct log_output *output,
|
||||
bool color, bool start, uint32_t level)
|
||||
{
|
||||
if (color) {
|
||||
const char *log_color = start && (colors[level] != NULL) ?
|
||||
colors[level] : LOG_COLOR_CODE_DEFAULT;
|
||||
print_formatted(log_output, "%s", log_color);
|
||||
print_formatted(output, "%s", log_color);
|
||||
}
|
||||
}
|
||||
|
||||
static void color_prefix(const struct log_output *log_output,
|
||||
static void color_prefix(const struct log_output *output,
|
||||
bool color, uint32_t level)
|
||||
{
|
||||
color_print(log_output, color, true, level);
|
||||
color_print(output, color, true, level);
|
||||
}
|
||||
|
||||
static void color_postfix(const struct log_output *log_output,
|
||||
static void color_postfix(const struct log_output *output,
|
||||
bool color, uint32_t level)
|
||||
{
|
||||
color_print(log_output, color, false, level);
|
||||
color_print(output, color, false, level);
|
||||
}
|
||||
|
||||
|
||||
static int ids_print(const struct log_output *log_output, bool level_on,
|
||||
static int ids_print(const struct log_output *output, bool level_on,
|
||||
bool func_on, uint32_t domain_id, uint32_t source_id, uint32_t level)
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
if (level_on) {
|
||||
total += print_formatted(log_output, "<%s> ", severity[level]);
|
||||
total += print_formatted(output, "<%s> ", severity[level]);
|
||||
}
|
||||
|
||||
total += print_formatted(log_output,
|
||||
total += print_formatted(output,
|
||||
(func_on &&
|
||||
((1 << level) & LOG_FUNCTION_PREFIX_MASK)) ?
|
||||
"%s." : "%s: ",
|
||||
|
@ -276,7 +275,7 @@ static void newline_print(const struct log_output *ctx, uint32_t flags)
|
|||
}
|
||||
|
||||
static void std_print(struct log_msg *msg,
|
||||
const struct log_output *log_output)
|
||||
const struct log_output *output)
|
||||
{
|
||||
const char *str = log_msg_str_get(msg);
|
||||
uint32_t nargs = log_msg_nargs_get(msg);
|
||||
|
@ -289,70 +288,70 @@ static void std_print(struct log_msg *msg,
|
|||
|
||||
switch (log_msg_nargs_get(msg)) {
|
||||
case 0:
|
||||
print_formatted(log_output, str);
|
||||
print_formatted(output, str);
|
||||
break;
|
||||
case 1:
|
||||
print_formatted(log_output, str, args[0]);
|
||||
print_formatted(output, str, args[0]);
|
||||
break;
|
||||
case 2:
|
||||
print_formatted(log_output, str, args[0], args[1]);
|
||||
print_formatted(output, str, args[0], args[1]);
|
||||
break;
|
||||
case 3:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2]);
|
||||
print_formatted(output, str, args[0], args[1], args[2]);
|
||||
break;
|
||||
case 4:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3]);
|
||||
break;
|
||||
case 5:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4]);
|
||||
break;
|
||||
case 6:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5]);
|
||||
break;
|
||||
case 7:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6]);
|
||||
break;
|
||||
case 8:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6], args[7]);
|
||||
break;
|
||||
case 9:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6], args[7],
|
||||
args[8]);
|
||||
break;
|
||||
case 10:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6], args[7],
|
||||
args[8], args[9]);
|
||||
break;
|
||||
case 11:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6], args[7],
|
||||
args[8], args[9], args[10]);
|
||||
break;
|
||||
case 12:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6], args[7],
|
||||
args[8], args[9], args[10], args[11]);
|
||||
break;
|
||||
case 13:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6], args[7],
|
||||
args[8], args[9], args[10], args[11], args[12]);
|
||||
break;
|
||||
case 14:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6], args[7],
|
||||
args[8], args[9], args[10], args[11], args[12],
|
||||
args[13]);
|
||||
break;
|
||||
case 15:
|
||||
print_formatted(log_output, str, args[0], args[1], args[2],
|
||||
print_formatted(output, str, args[0], args[1], args[2],
|
||||
args[3], args[4], args[5], args[6], args[7],
|
||||
args[8], args[9], args[10], args[11], args[12],
|
||||
args[13], args[14]);
|
||||
|
@ -364,62 +363,62 @@ static void std_print(struct log_msg *msg,
|
|||
}
|
||||
}
|
||||
|
||||
static void hexdump_line_print(const struct log_output *log_output,
|
||||
static void hexdump_line_print(const struct log_output *output,
|
||||
const uint8_t *data, uint32_t length,
|
||||
int prefix_offset, uint32_t flags)
|
||||
{
|
||||
newline_print(log_output, flags);
|
||||
newline_print(output, flags);
|
||||
|
||||
for (int i = 0; i < prefix_offset; i++) {
|
||||
print_formatted(log_output, " ");
|
||||
print_formatted(output, " ");
|
||||
}
|
||||
|
||||
for (int i = 0; i < HEXDUMP_BYTES_IN_LINE; i++) {
|
||||
if (i > 0 && !(i % 8)) {
|
||||
print_formatted(log_output, " ");
|
||||
print_formatted(output, " ");
|
||||
}
|
||||
|
||||
if (i < length) {
|
||||
print_formatted(log_output, "%02x ", data[i]);
|
||||
print_formatted(output, "%02x ", data[i]);
|
||||
} else {
|
||||
print_formatted(log_output, " ");
|
||||
print_formatted(output, " ");
|
||||
}
|
||||
}
|
||||
|
||||
print_formatted(log_output, "|");
|
||||
print_formatted(output, "|");
|
||||
|
||||
for (int i = 0; i < HEXDUMP_BYTES_IN_LINE; i++) {
|
||||
if (i > 0 && !(i % 8)) {
|
||||
print_formatted(log_output, " ");
|
||||
print_formatted(output, " ");
|
||||
}
|
||||
|
||||
if (i < length) {
|
||||
char c = (char)data[i];
|
||||
|
||||
print_formatted(log_output, "%c",
|
||||
print_formatted(output, "%c",
|
||||
isprint((int)c) ? c : '.');
|
||||
} else {
|
||||
print_formatted(log_output, " ");
|
||||
print_formatted(output, " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void hexdump_print(struct log_msg *msg,
|
||||
const struct log_output *log_output,
|
||||
const struct log_output *output,
|
||||
int prefix_offset, uint32_t flags)
|
||||
{
|
||||
uint32_t offset = 0U;
|
||||
uint8_t buf[HEXDUMP_BYTES_IN_LINE];
|
||||
size_t length;
|
||||
|
||||
print_formatted(log_output, "%s", log_msg_str_get(msg));
|
||||
print_formatted(output, "%s", log_msg_str_get(msg));
|
||||
|
||||
do {
|
||||
length = sizeof(buf);
|
||||
log_msg_hexdump_data_get(msg, buf, &length, offset);
|
||||
|
||||
if (length) {
|
||||
hexdump_line_print(log_output, buf, length,
|
||||
hexdump_line_print(output, buf, length,
|
||||
prefix_offset, flags);
|
||||
offset += length;
|
||||
} else {
|
||||
|
@ -429,34 +428,34 @@ static void hexdump_print(struct log_msg *msg,
|
|||
}
|
||||
|
||||
static void raw_string_print(struct log_msg *msg,
|
||||
const struct log_output *log_output)
|
||||
const struct log_output *output)
|
||||
{
|
||||
__ASSERT_NO_MSG(log_output->size);
|
||||
__ASSERT_NO_MSG(output->size);
|
||||
|
||||
size_t offset = 0;
|
||||
size_t length;
|
||||
bool eol = false;
|
||||
|
||||
do {
|
||||
length = log_output->size;
|
||||
length = output->size;
|
||||
/* Sting is stored in a hexdump message. */
|
||||
log_msg_hexdump_data_get(msg, log_output->buf, &length, offset);
|
||||
log_output->control_block->offset = length;
|
||||
log_msg_hexdump_data_get(msg, output->buf, &length, offset);
|
||||
output->control_block->offset = length;
|
||||
|
||||
if (length != 0) {
|
||||
eol = (log_output->buf[length - 1] == '\n');
|
||||
eol = (output->buf[length - 1] == '\n');
|
||||
}
|
||||
|
||||
log_output_flush(log_output);
|
||||
log_output_flush(output);
|
||||
offset += length;
|
||||
} while (length > 0);
|
||||
|
||||
if (eol) {
|
||||
print_formatted(log_output, "\r");
|
||||
print_formatted(output, "\r");
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t prefix_print(const struct log_output *log_output,
|
||||
static uint32_t prefix_print(const struct log_output *output,
|
||||
uint32_t flags, bool func_on, uint32_t timestamp, uint8_t level,
|
||||
uint8_t domain_id, uint16_t source_id)
|
||||
{
|
||||
|
@ -476,42 +475,42 @@ static uint32_t prefix_print(const struct log_output *log_output,
|
|||
static const int facility = 16; /* local0 */
|
||||
|
||||
length += print_formatted(
|
||||
log_output,
|
||||
output,
|
||||
"<%d>1 ",
|
||||
facility * 8 +
|
||||
level_to_rfc5424_severity(level));
|
||||
}
|
||||
|
||||
if (stamp) {
|
||||
length += timestamp_print(log_output, flags, timestamp);
|
||||
length += timestamp_print(output, flags, timestamp);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_BACKEND_NET) &&
|
||||
flags & LOG_OUTPUT_FLAG_FORMAT_SYSLOG) {
|
||||
length += print_formatted(
|
||||
log_output, "%s - - - - ",
|
||||
log_output->control_block->hostname ?
|
||||
log_output->control_block->hostname :
|
||||
output, "%s - - - - ",
|
||||
output->control_block->hostname ?
|
||||
output->control_block->hostname :
|
||||
"zephyr");
|
||||
} else {
|
||||
color_prefix(log_output, colors_on, level);
|
||||
color_prefix(output, colors_on, level);
|
||||
}
|
||||
|
||||
length += ids_print(log_output, level_on, func_on,
|
||||
length += ids_print(output, level_on, func_on,
|
||||
domain_id, source_id, level);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
static void postfix_print(const struct log_output *log_output,
|
||||
static void postfix_print(const struct log_output *output,
|
||||
uint32_t flags, uint8_t level)
|
||||
{
|
||||
color_postfix(log_output, (flags & LOG_OUTPUT_FLAG_COLORS),
|
||||
color_postfix(output, (flags & LOG_OUTPUT_FLAG_COLORS),
|
||||
level);
|
||||
newline_print(log_output, flags);
|
||||
newline_print(output, flags);
|
||||
}
|
||||
|
||||
void log_output_msg_process(const struct log_output *log_output,
|
||||
void log_output_msg_process(const struct log_output *output,
|
||||
struct log_msg *msg,
|
||||
uint32_t flags)
|
||||
{
|
||||
|
@ -525,27 +524,27 @@ void log_output_msg_process(const struct log_output *log_output,
|
|||
|
||||
if (IS_ENABLED(CONFIG_LOG_MIPI_SYST_ENABLE) &&
|
||||
flags & LOG_OUTPUT_FLAG_FORMAT_SYST) {
|
||||
log_output_msg_syst_process(log_output, msg, flags);
|
||||
log_output_msg_syst_process(output, msg, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
prefix_offset = raw_string ?
|
||||
0 : prefix_print(log_output, flags, std_msg, timestamp,
|
||||
0 : prefix_print(output, flags, std_msg, timestamp,
|
||||
level, domain_id, source_id);
|
||||
|
||||
if (log_msg_is_std(msg)) {
|
||||
std_print(msg, log_output);
|
||||
std_print(msg, output);
|
||||
} else if (raw_string) {
|
||||
raw_string_print(msg, log_output);
|
||||
raw_string_print(msg, output);
|
||||
} else {
|
||||
hexdump_print(msg, log_output, prefix_offset, flags);
|
||||
hexdump_print(msg, output, prefix_offset, flags);
|
||||
}
|
||||
|
||||
if (!raw_string) {
|
||||
postfix_print(log_output, flags, level);
|
||||
postfix_print(output, flags, level);
|
||||
}
|
||||
|
||||
log_output_flush(log_output);
|
||||
log_output_flush(output);
|
||||
}
|
||||
|
||||
static bool ends_with_newline(const char *fmt)
|
||||
|
@ -560,7 +559,7 @@ static bool ends_with_newline(const char *fmt)
|
|||
return (c == '\n');
|
||||
}
|
||||
|
||||
void log_output_string(const struct log_output *log_output,
|
||||
void log_output_string(const struct log_output *output,
|
||||
struct log_msg_ids src_level, uint32_t timestamp,
|
||||
const char *fmt, va_list ap, uint32_t flags)
|
||||
{
|
||||
|
@ -572,33 +571,33 @@ void log_output_string(const struct log_output *log_output,
|
|||
|
||||
if (IS_ENABLED(CONFIG_LOG_MIPI_SYST_ENABLE) &&
|
||||
flags & LOG_OUTPUT_FLAG_FORMAT_SYST) {
|
||||
log_output_string_syst_process(log_output,
|
||||
log_output_string_syst_process(output,
|
||||
src_level, fmt, ap, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!raw_string) {
|
||||
prefix_print(log_output, flags, true, timestamp,
|
||||
prefix_print(output, flags, true, timestamp,
|
||||
level, domain_id, source_id);
|
||||
}
|
||||
|
||||
length = cbvprintf(out_func, (void *)log_output, fmt, ap);
|
||||
length = cbvprintf(out_func, (void *)output, fmt, ap);
|
||||
|
||||
(void)length;
|
||||
|
||||
if (raw_string) {
|
||||
/* add \r if string ends with newline. */
|
||||
if (ends_with_newline(fmt)) {
|
||||
print_formatted(log_output, "\r");
|
||||
print_formatted(output, "\r");
|
||||
}
|
||||
} else {
|
||||
postfix_print(log_output, flags, level);
|
||||
postfix_print(output, flags, level);
|
||||
}
|
||||
|
||||
log_output_flush(log_output);
|
||||
log_output_flush(output);
|
||||
}
|
||||
|
||||
void log_output_hexdump(const struct log_output *log_output,
|
||||
void log_output_hexdump(const struct log_output *output,
|
||||
struct log_msg_ids src_level, uint32_t timestamp,
|
||||
const char *metadata, const uint8_t *data,
|
||||
uint32_t length, uint32_t flags)
|
||||
|
@ -610,49 +609,49 @@ void log_output_hexdump(const struct log_output *log_output,
|
|||
|
||||
if (IS_ENABLED(CONFIG_LOG_MIPI_SYST_ENABLE) &&
|
||||
flags & LOG_OUTPUT_FLAG_FORMAT_SYST) {
|
||||
log_output_hexdump_syst_process(log_output,
|
||||
log_output_hexdump_syst_process(output,
|
||||
src_level, data, length, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
prefix_offset = prefix_print(log_output, flags, true, timestamp,
|
||||
prefix_offset = prefix_print(output, flags, true, timestamp,
|
||||
level, domain_id, source_id);
|
||||
|
||||
/* Print metadata */
|
||||
print_formatted(log_output, "%s", metadata);
|
||||
print_formatted(output, "%s", metadata);
|
||||
|
||||
while (length) {
|
||||
uint32_t part_len = length > HEXDUMP_BYTES_IN_LINE ?
|
||||
HEXDUMP_BYTES_IN_LINE : length;
|
||||
|
||||
hexdump_line_print(log_output, data, part_len,
|
||||
hexdump_line_print(output, data, part_len,
|
||||
prefix_offset, flags);
|
||||
|
||||
data += part_len;
|
||||
length -= part_len;
|
||||
};
|
||||
|
||||
postfix_print(log_output, flags, level);
|
||||
log_output_flush(log_output);
|
||||
postfix_print(output, flags, level);
|
||||
log_output_flush(output);
|
||||
}
|
||||
|
||||
void log_output_dropped_process(const struct log_output *log_output, uint32_t cnt)
|
||||
void log_output_dropped_process(const struct log_output *output, uint32_t cnt)
|
||||
{
|
||||
char buf[5];
|
||||
int len;
|
||||
static const char prefix[] = DROPPED_COLOR_PREFIX "--- ";
|
||||
static const char postfix[] =
|
||||
" messages dropped ---\r\n" DROPPED_COLOR_POSTFIX;
|
||||
log_output_func_t outf = log_output->func;
|
||||
log_output_func_t outf = output->func;
|
||||
|
||||
cnt = MIN(cnt, 9999);
|
||||
len = snprintk(buf, sizeof(buf), "%d", cnt);
|
||||
|
||||
buffer_write(outf, (uint8_t *)prefix, sizeof(prefix) - 1,
|
||||
log_output->control_block->ctx);
|
||||
buffer_write(outf, buf, len, log_output->control_block->ctx);
|
||||
output->control_block->ctx);
|
||||
buffer_write(outf, buf, len, output->control_block->ctx);
|
||||
buffer_write(outf, (uint8_t *)postfix, sizeof(postfix) - 1,
|
||||
log_output->control_block->ctx);
|
||||
output->control_block->ctx);
|
||||
}
|
||||
|
||||
void log_output_timestamp_freq_set(uint32_t frequency)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue