diff mbox series

[v4,06/10] cxl: add logging functions for monitor

Message ID 166793222281.3768752.3333516400569686550.stgit@djiang5-desk3.ch.intel.com
State New, archived
Headers show
Series cxl: add monitor support for trace events | expand

Commit Message

Dave Jiang Nov. 8, 2022, 6:30 p.m. UTC
Duplicate log functions from ndctl/monitor to use for stdout and file
logging.

Signed-off-by: Dave Jiang <dave.jiang@gmail.com>
---
 cxl/monitor.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Verma, Vishal L Nov. 9, 2022, 12:31 a.m. UTC | #1
On Tue, 2022-11-08 at 11:30 -0700, Dave Jiang wrote:
> Duplicate log functions from ndctl/monitor to use for stdout and file
> logging.
> 
> Signed-off-by: Dave Jiang <dave.jiang@gmail.com>
> ---
>  cxl/monitor.c |   25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)

Hm we already have util/log.{c,h}. Lets move these and any other
relevant infra there, and then include those in ndctl/monitor and
cxl/monitor.

> 
> diff --git a/cxl/monitor.c b/cxl/monitor.c
> index c3f7e3639ec0..518d8142e40d 100644
> --- a/cxl/monitor.c
> +++ b/cxl/monitor.c
> @@ -39,6 +39,31 @@ static struct monitor {
>         bool human;
>  } monitor;
>  
> +static void log_standard(struct log_ctx *ctx, int priority, const char *file,
> +               int line, const char *fn, const char *format, va_list args)
> +{
> +       if (priority == 6)
> +               vfprintf(stdout, format, args);
> +       else
> +               vfprintf(stderr, format, args);
> +}
> +
> +static void log_file(struct log_ctx *ctx, int priority, const char *file,
> +               int line, const char *fn, const char *format, va_list args)
> +{
> +       FILE *f = monitor.log_file;
> +
> +       if (priority != LOG_NOTICE) {
> +               struct timespec ts;
> +
> +               clock_gettime(CLOCK_REALTIME, &ts);
> +               fprintf(f, "[%10ld.%09ld] [%d] ", ts.tv_sec, ts.tv_nsec, getpid());
> +       }
> +
> +       vfprintf(f, format, args);
> +       fflush(f);
> +}
> +
>  static int monitor_event(struct cxl_ctx *ctx)
>  {
>         int fd, epollfd, rc = 0, timeout = -1;
> 
>
diff mbox series

Patch

diff --git a/cxl/monitor.c b/cxl/monitor.c
index c3f7e3639ec0..518d8142e40d 100644
--- a/cxl/monitor.c
+++ b/cxl/monitor.c
@@ -39,6 +39,31 @@  static struct monitor {
 	bool human;
 } monitor;
 
+static void log_standard(struct log_ctx *ctx, int priority, const char *file,
+		int line, const char *fn, const char *format, va_list args)
+{
+	if (priority == 6)
+		vfprintf(stdout, format, args);
+	else
+		vfprintf(stderr, format, args);
+}
+
+static void log_file(struct log_ctx *ctx, int priority, const char *file,
+		int line, const char *fn, const char *format, va_list args)
+{
+	FILE *f = monitor.log_file;
+
+	if (priority != LOG_NOTICE) {
+		struct timespec ts;
+
+		clock_gettime(CLOCK_REALTIME, &ts);
+		fprintf(f, "[%10ld.%09ld] [%d] ", ts.tv_sec, ts.tv_nsec, getpid());
+	}
+
+	vfprintf(f, format, args);
+	fflush(f);
+}
+
 static int monitor_event(struct cxl_ctx *ctx)
 {
 	int fd, epollfd, rc = 0, timeout = -1;