From patchwork Wed Jun 20 11:30:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 166017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 61CB3B6FC3 for ; Wed, 20 Jun 2012 21:30:35 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ShJ7K-0001fs-5b for incoming@patchwork.ozlabs.org; Wed, 20 Jun 2012 11:30:34 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ShJ7I-0001fT-SF for fwts-devel@lists.ubuntu.com; Wed, 20 Jun 2012 11:30:32 +0000 Received: from cpc19-craw6-2-0-cust5.croy.cable.virginmedia.com ([77.102.228.6] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ShJ7I-00026g-LL for fwts-devel@lists.ubuntu.com; Wed, 20 Jun 2012 11:30:32 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 5/6] lib: log: move line counting to logging back-ends Date: Wed, 20 Jun 2012 12:30:28 +0100 Message-Id: <1340191829-27444-6-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1340191829-27444-1-git-send-email-colin.king@canonical.com> References: <1340191829-27444-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Rather than logging the line counting at the logging top level we should do the line counting at the logging back-end level since these are actually re-formatting the data and keeping track of the per-log line count. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Alex Hung --- src/lib/include/fwts_log.h | 2 +- src/lib/src/fwts_log.c | 2 -- src/lib/src/fwts_log_html.c | 1 + src/lib/src/fwts_log_json.c | 4 +++- src/lib/src/fwts_log_plaintext.c | 5 ++++- src/lib/src/fwts_log_xml.c | 4 +++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib/include/fwts_log.h b/src/lib/include/fwts_log.h index e1d360e..35f2801 100644 --- a/src/lib/include/fwts_log.h +++ b/src/lib/include/fwts_log.h @@ -87,7 +87,6 @@ typedef enum { typedef struct log_t { unsigned int magic; /* magic ID of the log */ fwts_list log_files; /* list of fwts_log_file */ - int line_number; /* keeps track of the line numbering */ char *owner; /* who is writing to this log */ } fwts_log; @@ -96,6 +95,7 @@ typedef struct log_t { */ typedef struct { FILE *fp; /* file descriptor for log */ + int line_number; /* keeps track of the line numbering */ fwts_log *log; /* parent log struct */ fwts_log_type type; /* log type */ fwts_log_filename_type filename_type; /* log filename type */ diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c index 5de609e..d1f7fe6 100644 --- a/src/lib/src/fwts_log.c +++ b/src/lib/src/fwts_log.c @@ -420,7 +420,6 @@ int fwts_log_printf(fwts_log *log, log_file->ops->print(log_file, field, level, status, label, prefix, buffer); } - log->line_number++; va_end(args); } @@ -460,7 +459,6 @@ void fwts_log_newline(fwts_log *log) if (log_file->ops && log_file->ops->newline) log_file->ops->newline(log_file); } - log->line_number++; } } diff --git a/src/lib/src/fwts_log_html.c b/src/lib/src/fwts_log_html.c index a040b43..09db3bc 100644 --- a/src/lib/src/fwts_log_html.c +++ b/src/lib/src/fwts_log_html.c @@ -343,6 +343,7 @@ static int fwts_log_print_html( fwts_log_html(log_file, "\n"); fflush(log_file->fp); + log_file->line_number++; /* not used, but bump it anyway */ return 0; } diff --git a/src/lib/src/fwts_log_json.c b/src/lib/src/fwts_log_json.c index 8dd65e4..75383a5 100644 --- a/src/lib/src/fwts_log_json.c +++ b/src/lib/src/fwts_log_json.c @@ -69,7 +69,7 @@ static int fwts_log_print_json( localtime_r(&now, &tm); header = json_object_new_object(); - json_object_object_add(header, "line_num", json_object_new_int(log_file->log->line_number)); + json_object_object_add(header, "line_num", json_object_new_int(log_file->line_number)); snprintf(tmpbuf, sizeof(tmpbuf), "%2.2d/%2.2d/%-2.2d", tm.tm_mday, tm.tm_mon + 1, (tm.tm_year+1900) % 100); json_object_object_add(header, "date", json_object_new_string(tmpbuf)); @@ -95,6 +95,7 @@ static int fwts_log_print_json( json_object_object_add(header, "log_text", json_object_new_string(buffer)); json_object_array_add(json_log, header); + log_file->line_number++; /* This is academic really */ return 0; } @@ -168,6 +169,7 @@ static void fwts_log_close_json(fwts_log_file *log_file) fwrite(str, 1, len, log_file->fp); fwrite("\n", 1, 1, log_file->fp); fflush(log_file->fp); + log_file->line_number++; json_object_put(json_stack[0].obj); } diff --git a/src/lib/src/fwts_log_plaintext.c b/src/lib/src/fwts_log_plaintext.c index 7381ae3..256c8a4 100644 --- a/src/lib/src/fwts_log_plaintext.c +++ b/src/lib/src/fwts_log_plaintext.c @@ -52,7 +52,7 @@ static int fwts_log_header_plaintext( ptr++; if (!strncmp(ptr, "line", 4)) { n += snprintf(buffer + n, len - n, - "%5.5d", log_file->log->line_number); + "%5.5d", log_file->line_number); ptr += 4; } if (!strncmp(ptr, "date", 4)) { @@ -139,6 +139,7 @@ static int fwts_log_print_plaintext( fwrite(text, 1, strlen(text), log_file->fp); fwrite("\n", 1, 1, log_file->fp); fflush(log_file->fp); + log_file->line_number++; len += strlen(text) + 1; } fwts_text_list_free(lines); @@ -171,6 +172,7 @@ static void fwts_log_underline_plaintext(fwts_log_file *log_file, const int ch) fwrite(buffer, 1, width, log_file->fp); fflush(log_file->fp); + log_file->line_number++; free(buffer); } @@ -183,6 +185,7 @@ static void fwts_log_newline_plaintext(fwts_log_file *log_file) { fwrite("\n", 1, 1, log_file->fp); fflush(log_file->fp); + log_file->line_number++; } fwts_log_ops fwts_log_plaintext_ops = { diff --git a/src/lib/src/fwts_log_xml.c b/src/lib/src/fwts_log_xml.c index 19e5e94..47ec35c 100644 --- a/src/lib/src/fwts_log_xml.c +++ b/src/lib/src/fwts_log_xml.c @@ -67,7 +67,7 @@ static int fwts_log_print_xml( fprintf(log_file->fp, "%*s%d\n", (xml_stack_index + 1) * XML_INDENT, - "", log_file->log->line_number); + "", log_file->line_number); fprintf(log_file->fp, "%*s%2.2d/%2.2d/%-2.2d\n", (xml_stack_index + 1) * XML_INDENT, @@ -102,6 +102,7 @@ static int fwts_log_print_xml( fprintf(log_file->fp, "%*s\n", xml_stack_index * XML_INDENT, ""); fflush(log_file->fp); + log_file->line_number++; return 0; } @@ -169,6 +170,7 @@ static void fwts_log_close_xml(fwts_log_file *log_file) fwrite("\n", 1, 1, log_file->fp); fflush(log_file->fp); + log_file->line_number++; } fwts_log_ops fwts_log_xml_ops = {