log: allow for message continuation
cover log: allow for message continuation
With the first patch it becomes possible to continue a log message with the same log level and category as the previous messages.
We need this facility to convert pr_cont() to use our logging drivers.
The second patch provides a unit test.
This patch is a prerequisite:
[PATCH 1/1] log: mute messages generated by log drivers
https://lists.denx.de/pipermail/u-boot/2020-September/426418.html
Heinrich Schuchardt (2):
log: allow for message continuation
test: log: test message continuation
common/log.c | 23 ++++++++++++++---- doc/develop/logging.rst | 6 +++++ include/log.h | 2 ++ test/log/Makefile | 4 +++- test/log/cont_test.c | 52 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 test/log/cont_test.c
--
2.28.0
PATCH 1/2 log: allow for message continuation
Some drivers use macro pr_cont() for continuing a message sent via printk. Hence if we want to convert printk messaging to using the logging system, we must support continuation of log messages too.
As pr_cont() does not provide a message level we need a means of remembering the last log level.
With the patch a pseudo log level LOGL_CONT as well as a pseudo log category LOGC_CONT are introduced. Using these results in the application of the same log level and category as in the previous log message.
--- common/log.c | 23 ++++++++++++++++++----- doc/develop/logging.rst | 6 ++++++ include/log.h | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-)
common/log.c +18 -5
@@ -183,10 +183,12 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)* log_dispatch() - Send a log record to all log devices for processing * * The log record is sent to each log device in turn, skipping those which have -* filters which block the record +* filters which block the record. * -* @rec: Log record to dispatch -* @return 0 (meaning success) +* All log messages created while processing log record @rec are ignored. +* +* @rec: log record to dispatch +* Return: 0 msg sent, 1 msg not sent while already dispatching another msg */ static int log_dispatch (struct log_rec *rec) {
@@ -199,7 +201,7 @@ static int log_dispatch(struct log_rec *rec)* as this might result in infinite recursion. */ if (processing_msg) -return 0 ; +return 1 ;/* Emit message */ processing_msg =1 ;
@@ -214,10 +216,18 @@ static int log_dispatch(struct log_rec *rec)int _log (enum log_category_t cat,enum log_level_t level,const char *file,int line,const char *func,const char *fmt, ...) { +static enum log_category_t logc_prev =LOGC_NONE ; +static enum log_level_t logl_prev =LOGL_INFO ;char buf[CONFIG_SYS_CBSIZE ];struct log_rec rec;va_list args; +/* Check for message continuation */ +if (cat ==LOGC_CONT ) + cat = logc_prev; +if (level ==LOGL_CONT ) + level = logl_prev; + rec.cat = cat; rec.level = level; rec.file = file;
@@ -232,7 +242,10 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, gd->log_drop_count++;return -ENOSYS ; } -log_dispatch (&rec); +if (!log_dispatch (&rec)) { + logc_prev = cat; + logl_prev = level; + }return 0 ; }
doc/develop/logging.rst +6 -0
@@ -38,6 +38,9 @@ There are a number logging levels available, in increasing order of verbosity: * LOGL_DEBUG_CONTENT - Debug message showing full message content * LOGL_DEBUG_IO - Debug message showing hardware I/O access +To continue a log message in a separate call of function log() use + +* LOGL_CONT - Use same log level as in previous call Logging category ----------------
@@ -56,6 +59,9 @@ The following main categories are defined: * LOGC_DT - Related to device tree control * LOGC_EFI - Related to EFI implementation +To continue a log message in a separate call of function log() use + +* LOGC_CONT - Use same category as in previous call Enabling logging ----------------
include/log.h +2 -0
@@ -35,6 +35,7 @@ enum log_level_t {LOGL_FIRST =LOGL_EMERG ,LOGL_MAX =LOGL_DEBUG_IO , + LOGL_CONT = -1, /* Use same log level as in previous call */ };/**
@@ -60,6 +61,7 @@ enum log_category_t {LOGC_COUNT ,/* Number of log categories */ LOGC_END ,/* Sentinel value for a list of log categories */ + LOGC_CONT = -1, /* Use same category as in previous call */ };/* Helper to cast a uclass ID to a log category */
--
2.28.0
PATCH 1/2 log: allow for message continuation
Hi Heinrich,
Quoted 49 lines · Heinrich Schuchardt
Some drivers use macro
pr_cont()for continuing a message sent via printk. Hence if we want to convert printk messaging to using the logging system, we must support continuation of log messages too.As
pr_cont()does not provide a message level we need a means of remembering the last log level.With the patch a pseudo log level
LOGL_CONTas well as a pseudo log categoryLOGC_CONTare introduced. Using these results in the application of the same log level and category as in the previous log message.Signed-off-by Heinrich Schuchardt <[email protected]>--- common/log.c | 23 ++++++++++++++++++----- doc/develop/logging.rst | 6 ++++++ include/log.h | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-)common/log.c +6
-4@@ -183,10 +183,12 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)* log_dispatch() - Send a log record to all log devices for processing * * The log record is sent to each log device in turn, skipping those which have -* filters which block the record +* filters which block the record. * -* @rec: Log record to dispatch -* @return 0 (meaning success) +* All log messages created while processing log record @rec are ignored. +* +* @rec: log record to dispatch +* Return: 0 msg sent, 1 msg not sent while already dispatching another msg */ static int log_dispatch (struct log_rec *rec) {@@ -199,7 +201,7 @@ static int log_dispatch(struct log_rec *rec)* as this might result in infinite recursion. */ if (processing_msg) -return 0 ; +return 1 ;/* Emit message */ processing_msg =1 ;
common/log.c static int log_dispatch(struct log_rec *rec) · line 220
Quoted 5 lines
common/log.c +2
-0@@ -214,10 +216,18 @@ static int log_dispatch(struct log_rec *rec)int _log (enum log_category_t cat,enum log_level_t level,const char *file,int line,const char *func,const char *fmt, ...) { +static enum log_category_t logc_prev =LOGC_NONE ; +static enum log_level_t logl_prev =LOGL_INFO ;
I don't think we can use static variables in logging. Perhaps we can use gobal_data?
common/log.c static int log_dispatch(struct log_rec *rec) · line 226
Quoted 6 lines
common/log.c +2
-0char buf[CONFIG_SYS_CBSIZE ];struct log_rec rec;va_list args; +/* Check for message continuation */ +if (cat ==LOGC_CONT )
Regards,
Simon
PATCH 1/2 log: allow for message continuation
Quoted 49 lines · Simon Glass
Hi Heinrich,
Quoted 46 lines · Heinrich Schuchardt
Some drivers use macro
pr_cont()for continuing a message sent via printk. Hence if we want to convert printk messaging to using the logging system, we must support continuation of log messages too.As
pr_cont()does not provide a message level we need a means of remembering the last log level.With the patch a pseudo log level
LOGL_CONTas well as a pseudo log categoryLOGC_CONTare introduced. Using these results in the application of the same log level and category as in the previous log message.Signed-off-by Heinrich Schuchardt <[email protected]>--- common/log.c | 23 ++++++++++++++++++----- doc/develop/logging.rst | 6 ++++++ include/log.h | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-)common/log.c +6
-4@@ -183,10 +183,12 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)* log_dispatch() - Send a log record to all log devices for processing * * The log record is sent to each log device in turn, skipping those which have -* filters which block the record +* filters which block the record. * -* @rec: Log record to dispatch -* @return 0 (meaning success) +* All log messages created while processing log record @rec are ignored. +* +* @rec: log record to dispatch +* Return: 0 msg sent, 1 msg not sent while already dispatching another msg */ static int log_dispatch (struct log_rec *rec) {@@ -199,7 +201,7 @@ static int log_dispatch(struct log_rec *rec)* as this might result in infinite recursion. */ if (processing_msg) -return 0 ; +return 1 ;
Quoted 11 lines
common/log.c static int log_dispatch(struct log_rec *rec) · line 220
Quoted 8 lines
common/log.c +2
-0/* Emit message */ processing_msg =1 ;@@ -214,10 +216,18 @@ static int log_dispatch(struct log_rec *rec)int _log (enum log_category_t cat,enum log_level_t level,const char *file,int line,const char *func,const char *fmt, ...) { +static enum log_category_t logc_prev =LOGC_NONE ; +static enum log_level_t logl_prev =LOGL_INFO ;I don't think we can use static variables in logging. Perhaps we can use
gobal_data?
Are you worried about relocation?
The initialization of the global data fields should be done in log_init() before gd->flags |= GD_FLG_LOG_READY; I assume.
Is the rest ok for you?
Best regards
Heinrich
Quoted 12 lines
common/log.c static int log_dispatch(struct log_rec *rec) · line 226
Quoted 8 lines
common/log.c +2
-0char buf[CONFIG_SYS_CBSIZE ];struct log_rec rec;va_list args; +/* Check for message continuation */ +if (cat ==LOGC_CONT )Regards,
Simon
PATCH 1/2 log: allow for message continuation
Hi Heinrich,
Quoted 63 lines · Heinrich Schuchardt
Quoted 49 lines · Simon Glass
Hi Heinrich,
Quoted 46 lines · Heinrich Schuchardt
Some drivers use macro
pr_cont()for continuing a message sent via printk. Hence if we want to convert printk messaging to using the logging system, we must support continuation of log messages too.As
pr_cont()does not provide a message level we need a means of remembering the last log level.With the patch a pseudo log level
LOGL_CONTas well as a pseudo log categoryLOGC_CONTare introduced. Using these results in the application of the same log level and category as in the previous log message.Signed-off-by Heinrich Schuchardt <[email protected]>--- common/log.c | 23 ++++++++++++++++++----- doc/develop/logging.rst | 6 ++++++ include/log.h | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-)common/log.c +6
-4@@ -183,10 +183,12 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)* log_dispatch() - Send a log record to all log devices for processing * * The log record is sent to each log device in turn, skipping those which have -* filters which block the record +* filters which block the record. * -* @rec: Log record to dispatch -* @return 0 (meaning success) +* All log messages created while processing log record @rec are ignored. +* +* @rec: log record to dispatch +* Return: 0 msg sent, 1 msg not sent while already dispatching another msg */ static int log_dispatch (struct log_rec *rec) {@@ -199,7 +201,7 @@ static int log_dispatch(struct log_rec *rec)* as this might result in infinite recursion. */ if (processing_msg) -return 0 ; +return 1 ;Quoted 11 lines
common/log.c static int log_dispatch(struct log_rec *rec) · line 220
Quoted 8 lines
common/log.c +2
-0/* Emit message */ processing_msg =1 ;@@ -214,10 +216,18 @@ static int log_dispatch(struct log_rec *rec)int _log (enum log_category_t cat,enum log_level_t level,const char *file,int line,const char *func,const char *fmt, ...) { +static enum log_category_t logc_prev =LOGC_NONE ; +static enum log_level_t logl_prev =LOGL_INFO ;I don't think we can use static variables in logging. Perhaps we can use
gobal_data?
Quoted 1 line
Are you worried about relocation?
Yes, and SPL.
Quoted 3 lines
The initialization of the global data fields should be done in
log_init()beforegd->flags|=GD_FLG_LOG_READY; I assume.
Yes.
Quoted 2 lines
Is the rest ok for you?
Yes. If you are adding new things to global_data you could convert default_log_level to a char to avoid using more space.
Quoted 18 lines
Best regards
Heinrich
Quoted 12 lines
common/log.c static int log_dispatch(struct log_rec *rec) · line 226
Quoted 8 lines
common/log.c +2
-0char buf[CONFIG_SYS_CBSIZE ];struct log_rec rec;va_list args; +/* Check for message continuation */ +if (cat ==LOGC_CONT )Regards,
Simon
PATCH 1/2 log: allow for message continuation
Hi Heinrich,
Quoted 75 lines · Simon Glass
Hi Heinrich,
Quoted 63 lines · Heinrich Schuchardt
Quoted 49 lines · Simon Glass
Hi Heinrich,
Quoted 46 lines · Heinrich Schuchardt
Some drivers use macro
pr_cont()for continuing a message sent via printk. Hence if we want to convert printk messaging to using the logging system, we must support continuation of log messages too.As
pr_cont()does not provide a message level we need a means of remembering the last log level.With the patch a pseudo log level
LOGL_CONTas well as a pseudo log categoryLOGC_CONTare introduced. Using these results in the application of the same log level and category as in the previous log message.Signed-off-by Heinrich Schuchardt <[email protected]>--- common/log.c | 23 ++++++++++++++++++----- doc/develop/logging.rst | 6 ++++++ include/log.h | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-)common/log.c +6
-4@@ -183,10 +183,12 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)* log_dispatch() - Send a log record to all log devices for processing * * The log record is sent to each log device in turn, skipping those which have -* filters which block the record +* filters which block the record. * -* @rec: Log record to dispatch -* @return 0 (meaning success) +* All log messages created while processing log record @rec are ignored. +* +* @rec: log record to dispatch +* Return: 0 msg sent, 1 msg not sent while already dispatching another msg */ static int log_dispatch (struct log_rec *rec) {@@ -199,7 +201,7 @@ static int log_dispatch(struct log_rec *rec)* as this might result in infinite recursion. */ if (processing_msg) -return 0 ; +return 1 ;Quoted 11 lines
common/log.c static int log_dispatch(struct log_rec *rec) · line 220
Quoted 8 lines
common/log.c +2
-0/* Emit message */ processing_msg =1 ;@@ -214,10 +216,18 @@ static int log_dispatch(struct log_rec *rec)int _log (enum log_category_t cat,enum log_level_t level,const char *file,int line,const char *func,const char *fmt, ...) { +static enum log_category_t logc_prev =LOGC_NONE ; +static enum log_level_t logl_prev =LOGL_INFO ;I don't think we can use static variables in logging. Perhaps we can use
gobal_data?Quoted 1 line
Are you worried about relocation?
Yes, and SPL.
Quoted 3 lines
The initialization of the global data fields should be done in
log_init()beforegd->flags|=GD_FLG_LOG_READY; I assume.
Quoted 8 lines
Yes.
Quoted 2 lines
Is the rest ok for you?
Yes. If you are adding new things to
global_datayou could convertdefault_log_levelto a char to avoid using more space.
Also I notice that the processing_msg variable in log.c crashes logging in SPL/TPL. Can you please move this to global_data too?
Regards,
Simon
PATCH 2/2 test: log: test message continuation
In reply to Heinrich SchuchardtProvide a unit test checking that a continuation message will use the same log level and log category as the previous message.
--- test/log/Makefile | 4 +++- test/log/cont_test.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/log/cont_test.c
test/log/Makefile +3 -1
@@ -12,7 +12,9 @@ ifdef CONFIG_SANDBOX obj-$(CONFIG_LOG_SYSLOG) += syslog_test.o endif -ifndef CONFIG_LOG +ifdef CONFIG_LOG +obj-$(CONFIG_CONSOLE_RECORD) += cont_test.o +else obj-$(CONFIG_CONSOLE_RECORD) += nolog_test.o endif
test/log/cont_test.c new file +52 -0
52 lines not on this page · raw message
--
2.28.0
PATCH 2/2 test: log: test message continuation
Quoted 10 lines · Heinrich Schuchardt
Provide a unit test checking that a continuation message will use the same log level and log category as the previous message.
Signed-off-by Heinrich Schuchardt <[email protected]>--- test/log/Makefile | 4 +++- test/log/cont_test.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/log/cont_test.c
PATCH 2/2 test: log: test message continuation
In reply to Heinrich SchuchardtQuoted 5 lines · Heinrich Schuchardt
Provide a unit test checking that a continuation message will use the same log level and log category as the previous message.
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Simon Glass <[email protected]>
[snip]
test/log/cont_test.c line 32
Quoted 1 line
test/log/cont_test.c new file +1
-0+log (LOGC_CONT ,LOGL_CONT ,"cc%d\n" ,2 );
These new values aren't defined, or I missed some other series. Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201010/4fa914cd/attachment.sig>
PATCH 2/2 test: log: test message continuation
Quoted 5 lines · Tom Rini
Quoted 3 lines · Heinrich Schuchardt
Provide a unit test checking that a continuation message will use the same log level and log category as the previous message.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Simon Glass <[email protected]>[snip]
test/log/cont_test.c line 32
Quoted 1 line
test/log/cont_test.c new file +1
-0+log (LOGC_CONT ,LOGL_CONT ,"cc%d\n" ,2 );These new values aren't defined, or I missed some other series. Thanks!
They should be defined in the first patch
Quoted 23 lines · Heinrich Schuchardt
include/log.h +2
-1@@ -35,6 +35,7 @@ enum log_level_t {LOGL_FIRST =LOGL_EMERG ,LOGL_MAX =LOGL_DEBUG_IO , + LOGL_CONT = -1, /* Use same log level as in previous call */ };/** @@ -60,6 +61,7 @@ enum log_category_t {LOGC_COUNT ,/* Number of log categories */ LOGC_END ,/* Sentinel value for a list of log categories */ + LOGC_CONT = -1, /* Use same category as in previous call */ };/* Helper to cast a uclass ID to a log category */ --2.28.0
PATCH 2/2 test: log: test message continuation
Quoted 8 lines · Sean Anderson
Quoted 7 lines · Tom Rini
Quoted 5 lines · Heinrich Schuchardt
Provide a unit test checking that a continuation message will use the same log level and log category as the previous message.
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Simon Glass <[email protected]>
Quoted 7 lines
Quoted 5 lines
[snip]
test/log/cont_test.c line 32
Quoted 1 line
test/log/cont_test.c new file +1
-0+log (LOGC_CONT ,LOGL_CONT ,"cc%d\n" ,2 );These new values aren't defined, or I missed some other series. Thanks!
They should be defined in the first patch
and I see 1/2 has changes requested, so I shoulda deferred this one. Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201010/d41b36cb/attachment.sig>
PATCH 2/2 test: log: test message continuation
Quoted 15 lines · Tom Rini
Quoted 14 lines · Sean Anderson
Quoted 12 lines · Tom Rini
Quoted 5 lines · Heinrich Schuchardt
Provide a unit test checking that a continuation message will use the same log level and log category as the previous message.
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Simon Glass <[email protected]>[snip]
test/log/cont_test.c line 32
Quoted 1 line
test/log/cont_test.c new file +1
-0+log (LOGC_CONT ,LOGL_CONT ,"cc%d\n" ,2 );These new values aren't defined, or I missed some other series. Thanks!
Quoted 5 lines
Quoted 1 line
They should be defined in the first patch
and I see 1/2 has changes requested, so I shoulda deferred this one. Thanks!
Hello Tom,
I am still waiting on the "doc: global data pointer" series to be merged as this will be the basis for adjusting the log continuation series.
https://patchwork.ozlabs.org/project/uboot/list/?series=205937
But I will be patient as it seems that you have been drowned in patches assigned to you.
Best regards
Heinrich
PATCH 2/2 test: log: test message continuation
In reply to Tom RiniQuoted 5 lines · Tom Rini
Quoted 3 lines · Heinrich Schuchardt
Provide a unit test checking that a continuation message will use the same log level and log category as the previous message.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Simon Glass <[email protected]>[snip]
test/log/cont_test.c line 32
Quoted 1 line
test/log/cont_test.c new file +1
-0+log (LOGC_CONT ,LOGL_CONT ,"cc%d\n" ,2 );These new values aren't defined, or I missed some other series. Thanks!
See here:
https://patchwork.ozlabs.org/project/uboot/patch/20200917121902.57403-2-xypron.glpk at gmx.de/
But the series has to be reworked.
Best regards
Heinrich