|
|
|
@ -8,6 +8,7 @@
|
|
|
|
package logpolicy
|
|
|
|
package logpolicy
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
@ -108,6 +109,15 @@ func logsDir() string {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// runningUnderSystemd reports whether we're running under systemd.
|
|
|
|
|
|
|
|
func runningUnderSystemd() bool {
|
|
|
|
|
|
|
|
if runtime.GOOS == "linux" && os.Getppid() == 1 {
|
|
|
|
|
|
|
|
slurp, _ := ioutil.ReadFile("/proc/1/stat")
|
|
|
|
|
|
|
|
return bytes.HasPrefix(slurp, []byte("1 (systemd) "))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// New returns a new log policy (a logger and its instance ID) for a
|
|
|
|
// New returns a new log policy (a logger and its instance ID) for a
|
|
|
|
// given collection name.
|
|
|
|
// given collection name.
|
|
|
|
func New(collection string) *Policy {
|
|
|
|
func New(collection string) *Policy {
|
|
|
|
@ -117,6 +127,11 @@ func New(collection string) *Policy {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
lflags = log.LstdFlags
|
|
|
|
lflags = log.LstdFlags
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if runningUnderSystemd() {
|
|
|
|
|
|
|
|
// If journalctl is going to prepend its own timestamp
|
|
|
|
|
|
|
|
// anyway, no need to add one.
|
|
|
|
|
|
|
|
lflags = 0
|
|
|
|
|
|
|
|
}
|
|
|
|
console := log.New(stderrWriter{}, "", lflags)
|
|
|
|
console := log.New(stderrWriter{}, "", lflags)
|
|
|
|
|
|
|
|
|
|
|
|
dir := logsDir()
|
|
|
|
dir := logsDir()
|
|
|
|
|