On Thu, Oct 12, 2017 at 7:23 PM, Qi, Fuli
>>> Let's use the same logging scheme as libndctl where we have 'struct
>>> log_ctx' and the the log function can be set to a custom routine. That
>>> way we can redirect log messages to syslog or structured json output
>>> simply by changing log_ctx.log_fn.
>> Thinking further about this, using log_ctx is probably not sufficient
>> either. We'll also need metadata with each event message, see the
>> extra fields that the systemd journal tracks for inspiration:
> When I was trying to replace syslog with libndctl logging scheme,
> I found that libndctl logging scheme only outputs to console.
> However there is no console in a nvdimm daemon. Users can't catch
> event messages from console, we should make the outputs to files or
> syslog instead.
> The follow are what I want to do.
> 1) add a new function log_event() into libndctl logging scheme
> As you mentioned, using log_ctx may not be sufficient, and in order to
> make adding metadata with each event message conveniently in the future,
> I am thinking about adding log_event() into libndctl logging scheme.
> The log_event() selects destination (file or syslog) of output depends on
> configuration, and outputs messages to the destination.
> 2) add LOG_NOTICE into log_priority
> Since there are only LOG_INFO, LOG_ERROR and LOG_DEBUG in log_priority now,
> I am also thinking about adding LOG_NOTICE into log_priority for event messages.
> I think the LOG_INFO level is too low for the event messages of nvdimm status,
> and its event is not up to LOG_ERROR level.
> Here is the summary of log_event() that I can think of for now.
> #define notice(x, arg...) log_notice(&(x)->ctx, ## arg)
> #define log_notice(ctx, arg...) log_cond(ctx, LOG_NOTICE, ##arg)
> //make the notice_out() to save event messages to output file
> #define notice_out(x, arg...) log_notice_out(&(x)->ctx, ## arg)
> #define log_notice_out(ctx, arg...) log_event(ctx, LOG_NOTICE, __FILE__, __LINE__,
__FUNCTION__, ## arg)
> void log_event(struct log_ctx *ctx, int priority, const char *file, int line,
> const char *fn, const char *format, ...)
> // check config items
> if(output_format = json)
> // output json format to output_path
> // output text format to output_path
> } else
> If you agree with this idea, I will implement it asap.
> Or if I had any misunderstanding, please kindly let me know.
Yes, I think this looks on the right track. My question is whether we
need a device name for the source of the log event rather than
function name and line number. Events can be associated with the bus,
dimms, regions, or namespace.
Sorry, I just referred to the original do_log(). As your mentioned,
I will change the parameters with a device name and think more
about the event's information what should be added.