Re: [ndctl PATCH] ndctl, monitor: add [--verbose] option to emit extra debug messages

2018-08-02 Thread Verma, Vishal L


On Thu, 2018-08-02 at 23:21 +0900, QI Fuli wrote:
> In the ndctl monitor, currently the debug messages cannot be outputted to log.
> This patch is used for adding [--verbose] option to ndctl monitor to emit
> debug messages. Also, the log level of some messages are changed by this 
> patch.
> 
> Cc: Masayoshi Mizuma 
> Signed-off-by: QI Fuli 
> ---
>  Documentation/ndctl/ndctl-monitor.txt |  4 
>  ndctl/monitor.c   | 20 +++-
>  2 files changed, 19 insertions(+), 5 deletions(-)

Looks good, applied.

> 
> diff --git a/Documentation/ndctl/ndctl-monitor.txt 
> b/Documentation/ndctl/ndctl-monitor.txt
> index 762073e..1cba9ea 100644
> --- a/Documentation/ndctl/ndctl-monitor.txt
> +++ b/Documentation/ndctl/ndctl-monitor.txt
> @@ -98,6 +98,10 @@ specified events.
>   Output monitor notification as human friendly json format instead
>   of the default machine friendly json format.
>  
> +-v::
> +--verbose::
> + Emit extra debug messages to log.
> +
>  COPYRIGHT
>  -
>  Copyright (c) 2018, FUJITSU LIMITED. License GPLv2: GNU GPL version 2
> diff --git a/ndctl/monitor.c b/ndctl/monitor.c
> index 4e5daf5..f10384b 100644
> --- a/ndctl/monitor.c
> +++ b/ndctl/monitor.c
> @@ -22,6 +22,7 @@ static struct monitor {
>   const char *dimm_event;
>   bool daemon;
>   bool human;
> + bool verbose;
>   unsigned int event_flags;
>  } monitor;
>  
> @@ -92,7 +93,9 @@ static void log_file(struct ndctl_ctx *ctx, int priority, 
> const char *file,
>   f = fopen(monitor.log, "a+");
>   if (!f) {
>   ndctl_set_log_fn(ctx, log_syslog);
> - fail("open logfile %s failed\n%s", monitor.log, buf);
> + err(ctx, "open logfile %s failed\n", monitor.log);
> + did_fail = 1;
> + notice(ctx, "%s\n", buf);
>   goto end;
>   }
>   fprintf(f, "%s", buf);
> @@ -390,8 +393,9 @@ static int monitor_event(struct ndctl_ctx *ctx,
>   if (util_dimm_event_filter(mdimm, monitor.event_flags)) 
> {
>   rc = notify_dimm_event(mdimm);
>   if (rc) {
> - fail("%s: notify dimm event failed\n",
> + err(ctx, "%s: notify dimm event 
> failed\n",
>   
> ndctl_dimm_get_devname(mdimm->dimm));
> + did_fail = 1;
>   goto out;
>   }
>   }
> @@ -506,7 +510,7 @@ static int read_config_file(struct ndctl_ctx *ctx, struct 
> monitor *_monitor,
>  
>   f = fopen(config_file, "r");
>   if (!f) {
> - fail("config-file: %s cannot be opened\n", config_file);
> + err(ctx, "config-file: %s cannot be opened\n", config_file);
>   rc = -errno;
>   goto out;
>   }
> @@ -587,6 +591,8 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
>   "run ndctl monitor as a daemon"),
>   OPT_BOOLEAN('u', "human", ,
>   "use human friendly output formats"),
> + OPT_BOOLEAN('v', "verbose", ,
> + "emit extra debug messages to log"),
>   OPT_END(),
>   };
>   const char * const u[] = {
> @@ -607,7 +613,11 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
>  
>   /* default to log_standard */
>   ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_standard);
> - ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_NOTICE);
> +
> + if (monitor.verbose)
> + ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_DEBUG);
> + else
> + ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_NOTICE);
>  
>   rc = read_config_file((struct ndctl_ctx *)ctx, , );
>   if (rc)
> @@ -629,7 +639,7 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
>   err((struct ndctl_ctx *)ctx, "daemon start failed\n");
>   goto out;
>   }
> - notice((struct ndctl_ctx *)ctx, "ndctl monitor daemon 
> started\n");
> + err((struct ndctl_ctx *)ctx, "ndctl monitor daemon started\n");
>   }
>  
>   if (parse_monitor_event(, (struct ndctl_ctx *)ctx))
___
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm


[ndctl PATCH] ndctl, monitor: add [--verbose] option to emit extra debug messages

2018-08-02 Thread QI Fuli
In the ndctl monitor, currently the debug messages cannot be outputted to log.
This patch is used for adding [--verbose] option to ndctl monitor to emit
debug messages. Also, the log level of some messages are changed by this patch.

Cc: Masayoshi Mizuma 
Signed-off-by: QI Fuli 
---
 Documentation/ndctl/ndctl-monitor.txt |  4 
 ndctl/monitor.c   | 20 +++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/Documentation/ndctl/ndctl-monitor.txt 
b/Documentation/ndctl/ndctl-monitor.txt
index 762073e..1cba9ea 100644
--- a/Documentation/ndctl/ndctl-monitor.txt
+++ b/Documentation/ndctl/ndctl-monitor.txt
@@ -98,6 +98,10 @@ specified events.
Output monitor notification as human friendly json format instead
of the default machine friendly json format.
 
+-v::
+--verbose::
+   Emit extra debug messages to log.
+
 COPYRIGHT
 -
 Copyright (c) 2018, FUJITSU LIMITED. License GPLv2: GNU GPL version 2
diff --git a/ndctl/monitor.c b/ndctl/monitor.c
index 4e5daf5..f10384b 100644
--- a/ndctl/monitor.c
+++ b/ndctl/monitor.c
@@ -22,6 +22,7 @@ static struct monitor {
const char *dimm_event;
bool daemon;
bool human;
+   bool verbose;
unsigned int event_flags;
 } monitor;
 
@@ -92,7 +93,9 @@ static void log_file(struct ndctl_ctx *ctx, int priority, 
const char *file,
f = fopen(monitor.log, "a+");
if (!f) {
ndctl_set_log_fn(ctx, log_syslog);
-   fail("open logfile %s failed\n%s", monitor.log, buf);
+   err(ctx, "open logfile %s failed\n", monitor.log);
+   did_fail = 1;
+   notice(ctx, "%s\n", buf);
goto end;
}
fprintf(f, "%s", buf);
@@ -390,8 +393,9 @@ static int monitor_event(struct ndctl_ctx *ctx,
if (util_dimm_event_filter(mdimm, monitor.event_flags)) 
{
rc = notify_dimm_event(mdimm);
if (rc) {
-   fail("%s: notify dimm event failed\n",
+   err(ctx, "%s: notify dimm event 
failed\n",

ndctl_dimm_get_devname(mdimm->dimm));
+   did_fail = 1;
goto out;
}
}
@@ -506,7 +510,7 @@ static int read_config_file(struct ndctl_ctx *ctx, struct 
monitor *_monitor,
 
f = fopen(config_file, "r");
if (!f) {
-   fail("config-file: %s cannot be opened\n", config_file);
+   err(ctx, "config-file: %s cannot be opened\n", config_file);
rc = -errno;
goto out;
}
@@ -587,6 +591,8 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
"run ndctl monitor as a daemon"),
OPT_BOOLEAN('u', "human", ,
"use human friendly output formats"),
+   OPT_BOOLEAN('v', "verbose", ,
+   "emit extra debug messages to log"),
OPT_END(),
};
const char * const u[] = {
@@ -607,7 +613,11 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
 
/* default to log_standard */
ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_standard);
-   ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_NOTICE);
+
+   if (monitor.verbose)
+   ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_DEBUG);
+   else
+   ndctl_set_log_priority((struct ndctl_ctx *)ctx, LOG_NOTICE);
 
rc = read_config_file((struct ndctl_ctx *)ctx, , );
if (rc)
@@ -629,7 +639,7 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
err((struct ndctl_ctx *)ctx, "daemon start failed\n");
goto out;
}
-   notice((struct ndctl_ctx *)ctx, "ndctl monitor daemon 
started\n");
+   err((struct ndctl_ctx *)ctx, "ndctl monitor daemon started\n");
}
 
if (parse_monitor_event(, (struct ndctl_ctx *)ctx))
-- 
2.18.0


___
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm