Log to /var/log/rttys.log when stdout is a terminal

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao
2019-04-27 22:18:00 +08:00
parent 87a92484f7
commit d75ef1bf32
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -22,5 +22,5 @@ require (
github.com/rakyll/statik v0.1.6
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.4.1
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 // indirect
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
)
+4
View File
@@ -26,6 +26,7 @@ import (
"encoding/hex"
"flag"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"io"
"os"
"runtime"
@@ -48,6 +49,9 @@ type RttysConfig struct {
}
func init() {
if terminal.IsTerminal(int(os.Stdout.Fd())) {
return
}
log.AddHook(lfshook.NewHook("/var/log/rttys.log", &log.TextFormatter{}))
}