All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: linux-cxl@vger.kernel.org
Cc: alison.schofield@intel.com, vishal.l.verma@intel.com,
	ira.weiny@intel.com, bwidawsk@kernel.org,
	dan.j.williams@intel.com, nafonten@amd.com,
	nvdimm@lists.linux.dev
Subject: [PATCH v2 6/9] cxl: add logging functions for monitor
Date: Mon, 19 Sep 2022 16:47:09 -0700	[thread overview]
Message-ID: <166363122964.3861186.7714736198829346130.stgit@djiang5-desk3.ch.intel.com> (raw)
In-Reply-To: <166363103019.3861186.3067220004819656109.stgit@djiang5-desk3.ch.intel.com>

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(+)

diff --git a/cxl/monitor.c b/cxl/monitor.c
index 759246926e05..c241ed31584f 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;



  parent reply	other threads:[~2022-09-19 23:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19 23:46 [PATCH v2 0/9] cxl: add monitor support for trace events Dave Jiang
2022-09-19 23:46 ` [PATCH v2 1/9] cxl: add helper function to parse trace event to json object Dave Jiang
2022-09-19 23:46 ` [PATCH v2 2/9] cxl: add helper to parse through all current events Dave Jiang
2022-09-21 21:09   ` Alison Schofield
2022-09-21 21:46     ` Dave Jiang
2022-09-19 23:46 ` [PATCH v2 3/9] cxl: add common function to enable event trace Dave Jiang
2022-09-19 23:46 ` [PATCH v2 4/9] cxl: add common function to disable " Dave Jiang
2022-09-19 23:47 ` [PATCH v2 5/9] cxl: add monitor function for event trace events Dave Jiang
2022-09-19 23:47 ` Dave Jiang [this message]
2022-09-19 23:47 ` [PATCH v2 7/9] cxl: add monitor command to cxl Dave Jiang
2022-09-19 23:47 ` [PATCH v2 8/9] cxl: add systemd service for monitor Dave Jiang
2022-09-19 23:47 ` [PATCH v2 9/9] cxl: add man page documentation " Dave Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=166363122964.3861186.7714736198829346130.stgit@djiang5-desk3.ch.intel.com \
    --to=dave.jiang@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=bwidawsk@kernel.org \
    --cc=dan.j.williams@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nafonten@amd.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.