Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src openlog(3): add LOG_PTRIM and LOG_NLOG log options.
details: https://anonhg.NetBSD.org/src/rev/103d6adff3f9
branches: trunk
changeset: 352238:103d6adff3f9
user: roy <roy%NetBSD.org@localhost>
date: Wed Mar 22 17:52:36 2017 +0000
description:
openlog(3): add LOG_PTRIM and LOG_NLOG log options.
syslog(3) is the one stop method of logging system events and diagnostics.
When debugging a daemon in the foreground on a terminal, each line is
prefixed with tag[pid]: which is very repetative and can take up valuable
screen estate.
LOG_PTRIM solves this by removing this prefix from stderr output.
There is also the case where the debugging could involve a dry-run and
syslog(3) calls would pollute the system log with incorrect data.
LOG_NLOG solves this by not writing the the system log, but allowing
LOG_PERROR to operate as before.
Initially discussed here:
https://mail-index.netbsd.org/tech-userlevel/2016/10/06/msg010330.html
diffstat:
lib/libc/gen/syslog.3 | 11 +++++++++--
lib/libc/gen/xsyslog.c | 20 +++++++++++++++++---
sys/sys/syslog.h | 4 +++-
3 files changed, 29 insertions(+), 6 deletions(-)
diffs (109 lines):
diff -r fea884da8ec5 -r 103d6adff3f9 lib/libc/gen/syslog.3
--- a/lib/libc/gen/syslog.3 Wed Mar 22 16:07:12 2017 +0000
+++ b/lib/libc/gen/syslog.3 Wed Mar 22 17:52:36 2017 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: syslog.3,v 1.30 2017/02/21 18:22:15 abhinav Exp $
+.\" $NetBSD: syslog.3,v 1.31 2017/03/22 17:52:36 roy Exp $
.\" $OpenBSD: syslog.3,v 1.25 2005/07/22 03:16:58 jaredy Exp $
.\"
.\" Copyright (c) 1985, 1991, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)syslog.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd May 3, 2010
+.Dd March 22, 2017
.Dt SYSLOG 3
.Os
.Sh NAME
@@ -295,6 +295,10 @@
Normally the open is delayed until the first message is logged.
Useful for programs that need to manage the order in which file
descriptors are allocated.
+.It Dv LOG_NLOG
+Stops syslog from writing to the system log.
+Only useful with
+.Dv LOG_PERROR .
.It Dv LOG_PERROR
Write the message to standard error output as well to the system log.
.It Dv LOG_PID
@@ -302,6 +306,9 @@
instantiations of daemons.
(This PID is placed within brackets
between the ident and the message.)
+.It Dv LOG_PTRIM
+Trim anything syslog added to the message before writing to
+standard error output.
.El
.Pp
The
diff -r fea884da8ec5 -r 103d6adff3f9 lib/libc/gen/xsyslog.c
--- a/lib/libc/gen/xsyslog.c Wed Mar 22 16:07:12 2017 +0000
+++ b/lib/libc/gen/xsyslog.c Wed Mar 22 17:52:36 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xsyslog.c,v 1.2 2017/01/12 01:58:39 christos Exp $ */
+/* $NetBSD: xsyslog.c,v 1.3 2017/03/22 17:52:36 roy Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)syslog.c 8.5 (Berkeley) 4/29/95";
#else
-__RCSID("$NetBSD: xsyslog.c,v 1.2 2017/01/12 01:58:39 christos Exp $");
+__RCSID("$NetBSD: xsyslog.c,v 1.3 2017/03/22 17:52:36 roy Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -301,11 +301,24 @@
/* Output to stderr if requested. */
if (data->log_stat & LOG_PERROR) {
+ struct iovec *piov;
+ int piovcnt;
+
iov[iovcnt].iov_base = __UNCONST(CRLF + 1);
iov[iovcnt].iov_len = 1;
- (void)writev(STDERR_FILENO, iov, iovcnt + 1);
+ if (data->log_stat & LOG_PTRIM) {
+ piov = &iov[iovcnt - 1];
+ piovcnt = 2;
+ } else {
+ piov = iov;
+ piovcnt = iovcnt + 1;
+ }
+ (void)writev(STDERR_FILENO, piov, piovcnt);
}
+ if (data->log_stat & LOG_NLOG)
+ goto out;
+
/* Get connected, output the message to the local logger. */
(*fun->lock)(data);
opened = !data->log_opened;
@@ -345,6 +358,7 @@
(void)close(fd);
}
+out:
if (!(*fun->unlock)(data) && opened)
_closelog_unlocked_r(data);
}
diff -r fea884da8ec5 -r 103d6adff3f9 sys/sys/syslog.h
--- a/sys/sys/syslog.h Wed Mar 22 16:07:12 2017 +0000
+++ b/sys/sys/syslog.h Wed Mar 22 17:52:36 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: syslog.h,v 1.40 2017/03/21 11:54:46 roy Exp $ */
+/* $NetBSD: syslog.h,v 1.41 2017/03/22 17:52:36 roy Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993
@@ -168,6 +168,8 @@
#define LOG_NDELAY 0x08 /* don't delay open */
#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
#define LOG_PERROR 0x20 /* log to stderr as well */
+#define LOG_PTRIM 0x40 /* trim tag and pid from messages to stderr */
+#define LOG_NLOG 0x80 /* don't write to the system log */
#ifndef _KERNEL
Home |
Main Index |
Thread Index |
Old Index