summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmake-release48
-rw-r--r--sd_daemon/log.go35
-rw-r--r--sd_daemon/log_test.go8
-rw-r--r--sd_daemon/log_util.go16
-rwxr-xr-xsd_daemon/log_util.go.gen2
5 files changed, 86 insertions, 23 deletions
diff --git a/make-release b/make-release
new file mode 100755
index 0000000..8646bc1
--- /dev/null
+++ b/make-release
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+# Copyright 2016-2018 Luke Shumaker
+set -e
+
+branch=$(git name-rev --name-only HEAD)
+if [[ $branch == master ]]; then
+ gitdir="$(git rev-parse --git-dir)"
+ workdir="${gitdir}/release"
+ exec 8>"${workdir}.lock"
+ flock 8
+
+ rm -rf -- "$workdir"
+ git worktree prune
+ git branch -D release.tmp &>/dev/null || true
+
+ unset GIT_INDEX_FILE
+ git worktree add -b release.tmp "${gitdir}/release" master
+ (
+ unset GIT_DIR GIT_WORK_TREE
+ cd "$workdir"
+
+ go generate ./...
+ git ls-files -z '*/.gitignore' | xargs -0r rm -f --
+
+ git add .
+ git commit -m "Generate artifacts"
+
+ git checkout release # Ensure it exists locally
+ git pull --no-edit -s ours # Avoid conflicts
+
+ # What we want is
+ #
+ # git merge --no-edit -s theirs release.tmp
+ #
+ # Unfortunately, there is no 'theirs' strategy; so we
+ # have to switch branches and do it backward with the
+ # 'ours' strategry, switch back, then merge the merge
+ # commit.
+ git checkout release.tmp
+ git merge --no-edit -s ours release
+ git checkout release
+ git merge release.tmp
+
+ git branch -d release.tmp
+ )
+ rm -rf -- "$workdir"
+ git worktree prune
+fi
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
diff --git a/sd_daemon/log_test.go b/sd_daemon/log_test.go
index 2f835a8..fe2f6f6 100644
--- a/sd_daemon/log_test.go
+++ b/sd_daemon/log_test.go
@@ -54,17 +54,17 @@ func TestLog(t *testing.T) {
for in, out := range testcases {
written = nil
- n, err := log.WriteString(in.pri, in.msg)
+ n, err := log.LogString(in.pri, in.msg)
if n != len(out) || string(written) != out || err != nil {
- t.Errorf("WriteString(%#v, %#v)\n -> expected:{%#v, %#v, %#v}\n -> got:{%#v, %#v, %#v}\n",
+ t.Errorf("LogString(%#v, %#v)\n -> expected:{%#v, %#v, %#v}\n -> got:{%#v, %#v, %#v}\n",
in.pri, in.msg,
len(out), nil, out,
n, err, string(written))
}
written = nil
- n, err = log.WriteBytes(in.pri, []byte(in.msg))
+ n, err = log.LogBytes(in.pri, []byte(in.msg))
if n != len(out) || string(written) != out || err != nil {
- t.Errorf("WriteBytes(%#v, %#v)\n -> expected:{%#v, %#v, %#v}\n -> got:{%#v, %#v, %#v}\n",
+ t.Errorf("LogBytes(%#v, %#v)\n -> expected:{%#v, %#v, %#v}\n -> got:{%#v, %#v, %#v}\n",
in.pri, in.msg,
len(out), nil, out,
n, err, string(written))
diff --git a/sd_daemon/log_util.go b/sd_daemon/log_util.go
index d244913..93e0897 100644
--- a/sd_daemon/log_util.go
+++ b/sd_daemon/log_util.go
@@ -7,48 +7,48 @@ import "log/syslog"
// Emerg writes a message with priority syslog.LOG_EMERG to the log.
func (l *Logger) Emerg(msg string) error {
- _, err := l.WriteString(syslog.LOG_EMERG, msg)
+ _, err := l.LogString(syslog.LOG_EMERG, msg)
return err
}
// Alert writes a message with priority syslog.LOG_ALERT to the log.
func (l *Logger) Alert(msg string) error {
- _, err := l.WriteString(syslog.LOG_ALERT, msg)
+ _, err := l.LogString(syslog.LOG_ALERT, msg)
return err
}
// Crit writes a message with priority syslog.LOG_CRIT to the log.
func (l *Logger) Crit(msg string) error {
- _, err := l.WriteString(syslog.LOG_CRIT, msg)
+ _, err := l.LogString(syslog.LOG_CRIT, msg)
return err
}
// Err writes a message with priority syslog.LOG_ERR to the log.
func (l *Logger) Err(msg string) error {
- _, err := l.WriteString(syslog.LOG_ERR, msg)
+ _, err := l.LogString(syslog.LOG_ERR, msg)
return err
}
// Warning writes a message with priority syslog.LOG_WARNING to the log.
func (l *Logger) Warning(msg string) error {
- _, err := l.WriteString(syslog.LOG_WARNING, msg)
+ _, err := l.LogString(syslog.LOG_WARNING, msg)
return err
}
// Notice writes a message with priority syslog.LOG_NOTICE to the log.
func (l *Logger) Notice(msg string) error {
- _, err := l.WriteString(syslog.LOG_NOTICE, msg)
+ _, err := l.LogString(syslog.LOG_NOTICE, msg)
return err
}
// Info writes a message with priority syslog.LOG_INFO to the log.
func (l *Logger) Info(msg string) error {
- _, err := l.WriteString(syslog.LOG_INFO, msg)
+ _, err := l.LogString(syslog.LOG_INFO, msg)
return err
}
// Debug writes a message with priority syslog.LOG_DEBUG to the log.
func (l *Logger) Debug(msg string) error {
- _, err := l.WriteString(syslog.LOG_DEBUG, msg)
+ _, err := l.LogString(syslog.LOG_DEBUG, msg)
return err
}
diff --git a/sd_daemon/log_util.go.gen b/sd_daemon/log_util.go.gen
index 9bebacf..0ad4ea2 100755
--- a/sd_daemon/log_util.go.gen
+++ b/sd_daemon/log_util.go.gen
@@ -28,7 +28,7 @@ EOF
cat <<EOF
// $pri writes a message with priority syslog.LOG_${pri^^} to the log.
func (l *Logger) $pri(msg string) error {
- _, err := l.WriteString(syslog.LOG_${pri^^}, msg)
+ _, err := l.LogString(syslog.LOG_${pri^^}, msg)
return err
}