mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 11:41:39 +00:00
logpolicy: don't log timestamp when running under systemd
It'll do it anyway. Makes journalctl -fu cleaner. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
2d48f92a82
commit
7fb8d873ac
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user