Determine if your stdout is a console
We use op/logging
[link] for logs now. One of its many features is printing out the time the message was logged:
credit: github.com/op/go-logging
The only thing is, when starting our binary as a systemd
service we see logs with journalct
who already adds the timestamp on its own, we get a double timestamp.
Fortunately, we can avoid it by checking if stdout
file descriptor is a tty or not.
Like so (credit: github.com/mattn/go-isatty):
package main
import (
"fmt"
"github.com/mattn/go-isatty"
"os"
)
func main() {
if isatty.IsTerminal(os.Stdout.Fd()) {
fmt.Println("Is Terminal")
} else {
fmt.Println("Is Not Terminal")
}
}
Happy logging!