summaryrefslogtreecommitdiff
path: root/sd_daemon/log.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-09-05 00:19:41 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-09-05 00:19:41 -0400
commit1abc491c413010093c48e108d24f91e15080682e (patch)
treec2ec19ce2b371b1b9ab331281e81abdf3c0cd4da /sd_daemon/log.go
parentce07ec5e3d5888a5068dff408c47cc9fef91f4b1 (diff)
parent0a43955333992153412a6b8a99b2825c3d0a74ca (diff)
Merge branch 'master' of https://git.lukeshu.com/go/libsystemd
Diffstat (limited to 'sd_daemon/log.go')
-rw-r--r--sd_daemon/log.go35
1 files changed, 25 insertions, 10 deletions
diff --git a/sd_daemon/log.go b/sd_daemon/log.go
index 138a07a..c8d8419 100644
--- a/sd_daemon/log.go
+++ b/sd_daemon/log.go
@@ -53,10 +53,7 @@ func NewLogger(w io.Writer) *Logger {
// Log is a Logger whose interface is very similar to syslog.Writer,
// but writes to os.Stderr under the assumption that stderr is
-// forwarded to syslog (or journald).
-//
-// You are encouraged to use stderr unless you have a good reason to
-// talk to syslog or journald directly.
+// forwarded to syslogd (or journald).
var Log = NewLogger(os.Stderr)
// Cheap version of
@@ -77,9 +74,9 @@ func appendPrefix(buf []byte, n syslog.Priority) []byte {
return append(buf, b[i:]...)
}
-// WriteString writes a message with the specified priority to the
+// LogString writes a message with the specified priority to the
// log.
-func (l *Logger) WriteString(pri syslog.Priority, msg string) (n int, err error) {
+func (l *Logger) LogString(pri syslog.Priority, msg string) (n int, err error) {
l.mu.Lock()
defer l.mu.Unlock()
@@ -114,10 +111,10 @@ func (l *Logger) WriteString(pri syslog.Priority, msg string) (n int, err error)
return l.out.Write(l.buf)
}
-// WriteString writes a message with the specified priority to the
+// LogBytes writes a message with the specified priority to the
// log.
-func (l *Logger) WriteBytes(pri syslog.Priority, msg []byte) (n int, err error) {
- // Copy/pasted from WriteString and
+func (l *Logger) LogBytes(pri syslog.Priority, msg []byte) (n int, err error) {
+ // Copy/pasted from LogString and
// * `strings.` -> `bytes.`
// * `"\n"` -> `[]byte{'\n'}`
l.mu.Lock()
@@ -148,13 +145,31 @@ func (l *Logger) WriteBytes(pri syslog.Priority, msg []byte) (n int, err error)
return l.out.Write(l.buf)
}
+// Write writes a message with priority syslog.LOG_INFO to the log;
+// implementing io.Writer.
+func (l *Logger) Write(msg []byte) (n int, err error) {
+ n, err = l.LogBytes(syslog.LOG_INFO, msg)
+ return n, err
+}
+
+// WriteString writes a message with priority syslog.LOG_INFO to the
+// log; implementing io.WriteString's interface.
+func (l *Logger) WriteString(msg string) (n int, err error) {
+ n, err = l.LogString(syslog.LOG_INFO, msg)
+ return n, err
+}
+
type loggerWriter struct {
log *Logger
pri syslog.Priority
}
func (lw loggerWriter) Write(p []byte) (n int, err error) {
- return lw.log.WriteBytes(lw.pri, p)
+ return lw.log.LogBytes(lw.pri, p)
+}
+
+func (lw loggerWriter) WriteString(p string) (n int, err error) {
+ return lw.log.LogString(lw.pri, p)
}
// Writer returns an io.Writer that writes messages with the specified