summaryrefslogtreecommitdiff
path: root/nslcd_systemd/log.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-12-18 23:08:41 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-12-18 23:08:41 -0500
commit02a94b4d90531bca217d6913bd3f1325f3742ff6 (patch)
tree79d3e2b4bb96592354000deefae6d383fd6fa9ba /nslcd_systemd/log.go
parent055b10405ea02fb7adb3867141dc56464fda9a90 (diff)
nslcd_systemd: give each connection a unique ID prefix for logging
Diffstat (limited to 'nslcd_systemd/log.go')
-rw-r--r--nslcd_systemd/log.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/nslcd_systemd/log.go b/nslcd_systemd/log.go
new file mode 100644
index 0000000..8a646f8
--- /dev/null
+++ b/nslcd_systemd/log.go
@@ -0,0 +1,45 @@
+// Copyright (C) 2017 Luke Shumaker <lukeshu@sbcglobal.net>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301 USA
+
+package nslcd_systemd
+
+import (
+ "io"
+
+ "git.lukeshu.com/go/libnslcd/nslcd_server"
+)
+
+type PrefixLogger struct {
+ Prefix string
+ Logger nslcd_server.Logger
+}
+
+func (pl PrefixLogger) Emerg(m string) error { return pl.Logger.Emerg(pl.Prefix + m) }
+func (pl PrefixLogger) Alert(m string) error { return pl.Logger.Alert(pl.Prefix + m) }
+func (pl PrefixLogger) Crit(m string) error { return pl.Logger.Crit(pl.Prefix + m) }
+func (pl PrefixLogger) Err(m string) error { return pl.Logger.Err(pl.Prefix + m) }
+func (pl PrefixLogger) Warning(m string) error { return pl.Logger.Warning(pl.Prefix + m) }
+func (pl PrefixLogger) Notice(m string) error { return pl.Logger.Notice(pl.Prefix + m) }
+func (pl PrefixLogger) Info(m string) error { return pl.Logger.Info(pl.Prefix + m) }
+func (pl PrefixLogger) Debug(m string) error { return pl.Logger.Debug(pl.Prefix + m) }
+
+func (pl PrefixLogger) Write(m []byte) (int, error) {
+ return pl.Logger.Write(append([]byte(pl.Prefix), m...))
+}
+func (pl PrefixLogger) WriteString(m string) (int, error) {
+ return io.WriteString(pl.Logger, pl.Prefix+m)
+}