forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.go
53 lines (44 loc) · 1.07 KB
/
logs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package commands
import (
"io"
"os"
"github.com/mattermost/mattermost-server/mlog/human"
"github.com/spf13/cobra"
)
var LogsCmd = &cobra.Command{
Use: "logs",
Short: "Display logs in a human-readable format",
RunE: logsCmdF,
}
func init() {
LogsCmd.Flags().Bool("logrus", false, "Use logrus for formatting.")
RootCmd.AddCommand(LogsCmd)
}
func logsCmdF(command *cobra.Command, args []string) error {
// check stdin to see if we have a pipe
fi, err := os.Stdin.Stat()
if err != nil {
return err
}
var input io.Reader
if fi.Size() == 0 && fi.Mode()&os.ModeNamedPipe == 0 {
file, err := os.Open("mattermost.log")
if err != nil {
return err
}
defer file.Close()
input = file
} else {
input = os.Stdin
}
var writer human.LogWriter
if flag, _ := command.Flags().GetBool("logrus"); flag {
writer = human.NewLogrusWriter(os.Stdout)
} else {
writer = human.NewSimpleWriter(os.Stdout)
}
human.ProcessLogs(input, writer)
return nil
}