Hi Heinrich,

On Sun, 14 Jun 2020 at 08:48, Heinrich Schuchardt <xypron.g...@gmx.de> wrote:
>
> The name of the function emitting a log message may be of interest for a
> developer but is distracting for normal users. See the example below:
>
>     try_load_entry() Booting: Debian
>
> Make the default format for log messages customizable. By default show
> only the message text.
>
> Signed-off-by: Heinrich Schuchardt <xypron.g...@gmx.de>
> ---
> v2:
>         adjust logging tests
>         adjust description of log command
> ---
>  cmd/log.c                 |  2 +-
>  common/Kconfig            | 18 ++++++++++++++++++
>  include/log.h             | 12 +++++++++++-
>  test/log/syslog_test.c    | 20 ++++++++++++++------
>  test/py/tests/test_log.py |  2 ++
>  5 files changed, 46 insertions(+), 8 deletions(-)
>
> diff --git a/cmd/log.c b/cmd/log.c
> index 78352b2cb9..2c91545c0d 100644
> --- a/cmd/log.c
> +++ b/cmd/log.c
> @@ -139,7 +139,7 @@ static char log_help_text[] =
>         "log format <fmt> - set log output format. <fmt> is a string where\n"
>         "\teach letter indicates something that should be displayed:\n"
>         "\tc=category, l=level, F=file, L=line number, f=function, m=msg\n"
> -       "\tor 'default', equivalent to 'fm', or 'all' for all\n"
> +       "\tor 'default', or 'all' for all\n"
>         "log rec <category> <level> <file> <line> <func> <message> - "
>                 "output a log record"
>         ;
> diff --git a/common/Kconfig b/common/Kconfig
> index 7872bc46cd..60cae77f20 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -792,6 +792,24 @@ config TPL_LOG_CONSOLE
>
>  endif
>
> +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_ERROR_RETURN
>         bool "Log all functions which return an error"
>         help
> diff --git a/include/log.h b/include/log.h
> index df65398c04..ec471c3a01 100644
> --- a/include/log.h
> +++ b/include/log.h
> @@ -411,7 +411,17 @@ enum log_fmt {
>         LOGF_MSG,
>
>         LOGF_COUNT,
> -       LOGF_DEFAULT = (1 << LOGF_FUNC) | (1 << LOGF_MSG),
> +       LOGF_DEFAULT =
> +#ifdef CONFIG_LOGF_FILE
> +               (1 << LOGF_FILE) |
> +#endif
> +#ifdef CONFIG_LOGF_LINE
> +               (1 << LOGF_LINE) |
> +#endif
> +#ifdef CONFIG_LOGF_FUNC
> +               (1 << LOGF_FUNC) |
> +#endif

I don't like having these #ifdefs here. Could we instead add a
function to common/log.c like log_get_default_format() that uses
IS_ENABLED to return the value?

> +               (1 << LOGF_MSG),
>         LOGF_ALL = 0x3f,
>  };
>

Regards,
Simon

Reply via email to