[PATCH 2/8] lib: move log line number into log struct
Alex Hung
alex.hung at canonical.com
Mon May 21 09:24:59 UTC 2012
On 05/16/2012 09:20 PM, Colin King wrote:
> From: Colin Ian King<colin.king at canonical.com>
>
> Signed-off-by: Colin Ian King<colin.king at canonical.com>
> ---
> src/lib/include/fwts_log.h | 3 ++-
> src/lib/include/fwts_summary.h | 2 +-
> src/lib/src/fwts_framework.c | 2 +-
> src/lib/src/fwts_log.c | 14 ++++++--------
> src/lib/src/fwts_summary.c | 4 ++--
> 5 files changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/src/lib/include/fwts_log.h b/src/lib/include/fwts_log.h
> index 8848ad0..ab94029 100644
> --- a/src/lib/include/fwts_log.h
> +++ b/src/lib/include/fwts_log.h
> @@ -58,6 +58,7 @@ typedef struct log_t {
> FILE *fp;
> char *owner;
> int line_width;
> + int line_number;
> } fwts_log;
>
> fwts_log *fwts_log_open(const char* owner, const char *name, const char *mode);
> @@ -75,7 +76,7 @@ void fwts_log_filter_set_field(const fwts_log_field filter);
> void fwts_log_filter_unset_field(const fwts_log_field filter);
> int fwts_log_str_to_level(const char *str);
> char *fwts_log_level_to_str(const fwts_log_level level);
> -int fwts_log_line_number(void);
> +int fwts_log_line_number(fwts_log *log);
> void fwts_log_set_line_width(const int width);
>
> #define fwts_log_result(fw, fmt, args...) \
> diff --git a/src/lib/include/fwts_summary.h b/src/lib/include/fwts_summary.h
> index 260ac23..6478020 100644
> --- a/src/lib/include/fwts_summary.h
> +++ b/src/lib/include/fwts_summary.h
> @@ -27,7 +27,7 @@
>
> int fwts_summary_init(void);
> void fwts_summary_deinit(void);
> -int fwts_summary_add(const char *test, fwts_log_level level, char *text);
> +int fwts_summary_add(fwts_framework *fw, const char *test, fwts_log_level level, char *text);
> int fwts_summary_report(fwts_framework *fw, fwts_list *test_list);
>
> #endif
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 0d0911b..da24b71 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -716,7 +716,7 @@ void fwts_framework_log(fwts_framework *fw,
> break;
> case FWTS_FRAMEWORK_FAILED:
> fw->failed_level |= level;
> - fwts_summary_add(fw->current_major_test->name, level, buffer);
> + fwts_summary_add(fw, fw->current_major_test->name, level, buffer);
> fwts_log_printf(fw->results, LOG_RESULT, level, "%s [%s] %s: Test %d, %s",
> str, fwts_log_level_to_str(level), label, fw->current_minor_test_num, buffer);
> break;
> diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
> index 19fbe37..8eeeba2 100644
> --- a/src/lib/src/fwts_log.c
> +++ b/src/lib/src/fwts_log.c
> @@ -32,8 +32,6 @@
>
> static int log_line_width = 0;
>
> -static int fwts_log_line = 1;
> -
> static fwts_log_field fwts_log_filter = ~0;
>
> static char fwts_log_format[256] = "";
> @@ -52,9 +50,9 @@ void fwts_log_set_line_width(int width)
> * fwts_log_line_number()
> * get current line number of log
> */
> -int fwts_log_line_number(void)
> +int fwts_log_line_number(fwts_log *log)
> {
> - return fwts_log_line;
> + return log->line_number;
> }
>
> /*
> @@ -263,7 +261,7 @@ static int fwts_log_header(fwts_log *log, char *buffer, const int len, const fwt
> ptr++;
> if (strncmp(ptr,"line",4)==0) {
> n += snprintf(buffer+n, len-n,
> - "%5.5d", fwts_log_line);
> + "%5.5d", log->line_number);
> ptr+=4;
> }
> if (strncmp(ptr,"date",4)==0) {
> @@ -363,7 +361,7 @@ int fwts_log_vprintf(fwts_log *log, const fwts_log_field field, const fwts_log_l
> fwrite(text, 1, strlen(text), log->fp);
> fwrite("\n", 1, 1, log->fp);
> fflush(log->fp);
> - fwts_log_line++;
> + log->line_number++;
> len += strlen(text) + 1;
> }
> fwts_text_list_free(lines);
> @@ -396,7 +394,7 @@ void fwts_log_underline(fwts_log *log, const int ch)
>
> fwrite(buffer, 1, log->line_width, log->fp);
> fflush(log->fp);
> - fwts_log_line++;
> + log->line_number++;
> }
>
> /*
> @@ -408,7 +406,7 @@ void fwts_log_newline(fwts_log *log)
> if (log&& (log->magic == LOG_MAGIC)) {
> fwrite("\n", 1, 1, log->fp);
> fflush(log->fp);
> - fwts_log_line++;
> + log->line_number++;
> }
> }
>
> diff --git a/src/lib/src/fwts_summary.c b/src/lib/src/fwts_summary.c
> index 19038b9..192043d 100644
> --- a/src/lib/src/fwts_summary.c
> +++ b/src/lib/src/fwts_summary.c
> @@ -118,7 +118,7 @@ static int fwts_summary_level_to_index(fwts_log_level level)
> * add an error summary for a test with error message text at given
> * error level to the list of summaries.
> */
> -int fwts_summary_add(const char *test, fwts_log_level level, char *text)
> +int fwts_summary_add(fwts_framework *fw, const char *test, fwts_log_level level, char *text)
> {
> fwts_list_link *item;
> fwts_summary_item *summary_item = NULL;
> @@ -161,7 +161,7 @@ int fwts_summary_add(const char *test, fwts_log_level level, char *text)
>
> /* Now append a new line number to list of line numbers */
>
> - *line_num = fwts_log_line_number();
> + *line_num = fwts_log_line_number(fw->results);
> fwts_list_append(&summary_item->log_lines, line_num);
>
> /* And append new item if not done so already */
Acked-by: Alex Hung <alex.hung at canonical.com>
More information about the fwts-devel
mailing list