From 02a94b4d90531bca217d6913bd3f1325f3742ff6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 18 Dec 2017 23:08:41 -0500 Subject: nslcd_systemd: give each connection a unique ID prefix for logging --- nslcd_systemd/log.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 nslcd_systemd/log.go (limited to 'nslcd_systemd/log.go') 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 +// +// 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) +} -- cgit v1.2.3