Print messages to the syslog by default.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-01-08 11:44:42 +01:00
parent 222c9bb62b
commit 86ddff4a0a
2 changed files with 19 additions and 1 deletions

18
print.c
View File

@ -19,18 +19,30 @@
#include <stdarg.h>
#include <stdio.h>
#include <sys/types.h>
#include <syslog.h>
#include <unistd.h>
#include "print.h"
static int verbose = 1;
static int verbose;
static int print_level = LOG_INFO;
static int use_syslog = 1;
void print_no_syslog(void)
{
use_syslog = 0;
}
void print_set_level(int level)
{
print_level = level;
}
void print_verbose(void)
{
verbose = 1;
}
void print(int level, char const *format, ...)
{
pid_t pid;
@ -48,5 +60,9 @@ void print(int level, char const *format, ...)
if (verbose) {
fprintf(stdout, "ptp4l[%d]: %s\n", pid, buf);
fflush(stdout);
}
if (use_syslog) {
syslog(level, "[%d] %s", pid, buf);
}
}

View File

@ -24,7 +24,9 @@
void print(int level, char const *format, ...);
void print_no_syslog(void);
void print_set_level(int level);
void print_verbose(void);
#define pr_emerg(x...) print(LOG_EMERG, x)
#define pr_alert(x...) print(LOG_ALERT, x)