diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/Kconfig | 18 | ||||
-rw-r--r-- | common/console.c | 28 | ||||
-rw-r--r-- | common/log.c | 6 | ||||
-rw-r--r-- | common/log_console.c | 14 | ||||
-rw-r--r-- | common/log_syslog.c | 14 |
5 files changed, 59 insertions, 21 deletions
diff --git a/common/Kconfig b/common/Kconfig index 7872bc46cd..67b3818fde 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -699,6 +699,24 @@ config LOG_CONSOLE log message is shown - other details like level, category, file and line number are omitted. +config LOGF_FILE + bool "Show source file name in log messages by default" + help + Show the source file name in log messages by default. This value + can be overridden using the 'log format' command. + +config LOGF_LINE + bool "Show source line number in log messages by default" + help + Show the source line number in log messages by default. This value + can be overridden using the 'log format' command. + +config LOGF_FUNC + bool "Show function name in log messages by default" + help + Show the function name in log messages by default. This value can + be overridden using the 'log format' command. + config LOG_SYSLOG bool "Log output to syslog server" depends on NET diff --git a/common/console.c b/common/console.c index 7b9816979a..07c483f820 100644 --- a/common/console.c +++ b/common/console.c @@ -229,18 +229,34 @@ static void console_putc(int file, const char c) } } -static void console_puts_noserial(int file, const char *s) +/** + * console_puts_select() - Output a string to all console devices + * + * @file: File number to output to (e,g, stdout, see stdio.h) + * @serial_only: true to output only to serial, false to output to everything + * else + * @s: String to output + */ +static void console_puts_select(int file, bool serial_only, const char *s) { int i; struct stdio_dev *dev; for (i = 0; i < cd_count[file]; i++) { + bool is_serial; + dev = console_devices[file][i]; - if (dev->puts != NULL && !console_dev_is_serial(dev)) + is_serial = console_dev_is_serial(dev); + if (dev->puts && serial_only == is_serial) dev->puts(dev, s); } } +void console_puts_select_stderr(bool serial_only, const char *s) +{ + console_puts_select(stderr, serial_only, s); +} + static void console_puts(int file, const char *s) { int i; @@ -275,9 +291,9 @@ static inline void console_putc(int file, const char c) stdio_devices[file]->putc(stdio_devices[file], c); } -static inline void console_puts_noserial(int file, const char *s) +void console_puts_select(int file, bool serial_only, const char *s) { - if (!console_dev_is_serial(stdio_devices[file])) + if (serial_only == console_dev_is_serial(stdio_devices[file])) stdio_devices[file]->puts(stdio_devices[file], s); } @@ -489,7 +505,7 @@ static void print_pre_console_buffer(int flushpoint) puts(buf_out); break; case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL: - console_puts_noserial(stdout, buf_out); + console_puts_select(stdout, false, buf_out); break; } } @@ -776,7 +792,7 @@ int console_announce_r(void) display_options_get_banner(false, buf, sizeof(buf)); - console_puts_noserial(stdout, buf); + console_puts_select(stdout, false, buf); #endif return 0; diff --git a/common/log.c b/common/log.c index c5b9b489ca..734d26de4a 100644 --- a/common/log.c +++ b/common/log.c @@ -45,7 +45,11 @@ const char *log_get_cat_name(enum log_category_t cat) if (cat >= LOGC_NONE) return log_cat_name[cat - LOGC_NONE]; +#if CONFIG_IS_ENABLED(DM) name = uclass_get_name((enum uclass_id)cat); +#else + name = NULL; +#endif return name ? name : "<missing>"; } @@ -317,7 +321,7 @@ int log_init(void) gd->flags |= GD_FLG_LOG_READY; if (!gd->default_log_level) gd->default_log_level = CONFIG_LOG_DEFAULT_LEVEL; - gd->log_fmt = LOGF_DEFAULT; + gd->log_fmt = log_get_default_format(); return 0; } diff --git a/common/log_console.c b/common/log_console.c index 0b5b7089af..bb3f8464b9 100644 --- a/common/log_console.c +++ b/common/log_console.c @@ -25,18 +25,18 @@ static int log_console_emit(struct log_device *ldev, struct log_rec *rec) * - function is an identifier and ends with () * - message has a space before it unless it is on its own */ - if (fmt & (1 << LOGF_LEVEL)) + if (fmt & BIT(LOGF_LEVEL)) printf("%s.", log_get_level_name(rec->level)); - if (fmt & (1 << LOGF_CAT)) + if (fmt & BIT(LOGF_CAT)) printf("%s,", log_get_cat_name(rec->cat)); - if (fmt & (1 << LOGF_FILE)) + if (fmt & BIT(LOGF_FILE)) printf("%s:", rec->file); - if (fmt & (1 << LOGF_LINE)) + if (fmt & BIT(LOGF_LINE)) printf("%d-", rec->line); - if (fmt & (1 << LOGF_FUNC)) + if (fmt & BIT(LOGF_FUNC)) printf("%s()", rec->func); - if (fmt & (1 << LOGF_MSG)) - printf("%s%s", fmt != (1 << LOGF_MSG) ? " " : "", rec->msg); + if (fmt & BIT(LOGF_MSG)) + printf("%s%s", fmt != BIT(LOGF_MSG) ? " " : "", rec->msg); return 0; } diff --git a/common/log_syslog.c b/common/log_syslog.c index 698c585fa1..149ff5af31 100644 --- a/common/log_syslog.c +++ b/common/log_syslog.c @@ -82,21 +82,21 @@ static int log_syslog_emit(struct log_device *ldev, struct log_rec *rec) if (log_hostname) append(&ptr, msg_end, "%s ", log_hostname); append(&ptr, msg_end, "uboot: "); - if (fmt & (1 << LOGF_LEVEL)) + if (fmt & BIT(LOGF_LEVEL)) append(&ptr, msg_end, "%s.", log_get_level_name(rec->level)); - if (fmt & (1 << LOGF_CAT)) + if (fmt & BIT(LOGF_CAT)) append(&ptr, msg_end, "%s,", log_get_cat_name(rec->cat)); - if (fmt & (1 << LOGF_FILE)) + if (fmt & BIT(LOGF_FILE)) append(&ptr, msg_end, "%s:", rec->file); - if (fmt & (1 << LOGF_LINE)) + if (fmt & BIT(LOGF_LINE)) append(&ptr, msg_end, "%d-", rec->line); - if (fmt & (1 << LOGF_FUNC)) + if (fmt & BIT(LOGF_FUNC)) append(&ptr, msg_end, "%s()", rec->func); - if (fmt & (1 << LOGF_MSG)) + if (fmt & BIT(LOGF_MSG)) append(&ptr, msg_end, "%s%s", - fmt != (1 << LOGF_MSG) ? " " : "", rec->msg); + fmt != BIT(LOGF_MSG) ? " " : "", rec->msg); /* Consider trailing 0x00 */ ptr++; |