mirror of
https://github.com/linux-msm/qrtr.git
synced 2025-12-24 14:06:30 +01:00
logging: add use_syslog to qlog_setup
This causes qlog to log to syslog instead of logging to stderr. Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
This commit is contained in:
committed by
Bjorn Andersson
parent
f64c25c8af
commit
de5ee77b00
@@ -1,3 +1,4 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
@@ -7,9 +8,12 @@
|
||||
static const char default_tag[] = "libqrtr";
|
||||
static const char *current_tag = default_tag;
|
||||
|
||||
void qlog_setup(const char *tag)
|
||||
static bool logging_to_syslog = false;
|
||||
|
||||
void qlog_setup(const char *tag, bool use_syslog)
|
||||
{
|
||||
current_tag = tag;
|
||||
logging_to_syslog = use_syslog;
|
||||
}
|
||||
|
||||
static const char *get_priority_string(int priority)
|
||||
@@ -37,13 +41,18 @@ static const char *get_priority_string(int priority)
|
||||
|
||||
void qlog(int priority, const char *format, ...)
|
||||
{
|
||||
char buf[QLOG_BUF_SIZE];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vsnprintf(buf, QLOG_BUF_SIZE, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stderr, "%s %s: %s\n",
|
||||
get_priority_string(priority), current_tag, buf);
|
||||
if (logging_to_syslog) {
|
||||
vsyslog(priority, format, ap);
|
||||
} else {
|
||||
char buf[QLOG_BUF_SIZE];
|
||||
vsnprintf(buf, QLOG_BUF_SIZE, format, ap);
|
||||
|
||||
fprintf(stderr, "%s %s: %s\n",
|
||||
get_priority_string(priority), current_tag, buf);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef _QRTR_LOGGING_H_
|
||||
#define _QRTR_LOGGING_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -10,7 +11,7 @@
|
||||
#define __PRINTF__(fmt, args)
|
||||
#endif
|
||||
|
||||
void qlog_setup(const char *tag);
|
||||
void qlog_setup(const char *tag, bool use_syslog);
|
||||
|
||||
void qlog(int priority, const char *format, ...) __PRINTF__(2, 3);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ int main(int argc, char **argv)
|
||||
char *ep;
|
||||
const char *progname = basename(argv[0]);
|
||||
|
||||
qlog_setup(progname);
|
||||
qlog_setup(progname, false);
|
||||
|
||||
if (argc != 2)
|
||||
usage(progname);
|
||||
|
||||
@@ -107,7 +107,7 @@ int main(int argc, char **argv)
|
||||
int rc;
|
||||
const char *progname = basename(argv[0]);
|
||||
|
||||
qlog_setup(progname);
|
||||
qlog_setup(progname, false);
|
||||
|
||||
rc = 0;
|
||||
memset(&pkt, 0, sizeof(pkt));
|
||||
|
||||
Reference in New Issue
Block a user