support alternative output streams
Gitea/etcdmtr/pipeline/head This commit looks good
Details
Gitea/etcdmtr/pipeline/head This commit looks good
Details
This commit is contained in:
parent
5f8061378a
commit
13509f98c4
|
@ -92,10 +92,6 @@ func (c *Client) GetEtcdWithEndpoints(endpoints []string) (*clientv3.Client, err
|
|||
})
|
||||
}
|
||||
|
||||
func getLogger() *etcdmtr.ELog {
|
||||
return etcdmtr.NewRootLogger()
|
||||
}
|
||||
|
||||
func main() {
|
||||
args := &EtcdMtrArgs{}
|
||||
positionals, err := flags.Parse(args)
|
||||
|
@ -109,7 +105,7 @@ func main() {
|
|||
os.Exit(2)
|
||||
}
|
||||
|
||||
logger := getLogger()
|
||||
logger := etcdmtr.NewRootLogger()
|
||||
|
||||
if args.Version {
|
||||
logger.Fatalc(1, "0.0.1")
|
||||
|
|
|
@ -2,6 +2,7 @@ package etcdmtr
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -24,13 +25,6 @@ func (l LogLevel) String() string {
|
|||
return LOGLEVEL_NAMES[l]
|
||||
}
|
||||
|
||||
type ELog struct {
|
||||
parent *ELog
|
||||
name string
|
||||
Level LogLevel
|
||||
Format *LogFormat
|
||||
}
|
||||
|
||||
type LogFormatTokenValue int64
|
||||
|
||||
const (
|
||||
|
@ -91,6 +85,14 @@ func (f *LogFormat) AppendTimestamp(format string) *LogFormat {
|
|||
})
|
||||
}
|
||||
|
||||
type ELog struct {
|
||||
parent *ELog
|
||||
name string
|
||||
Level LogLevel
|
||||
Format *LogFormat
|
||||
Output io.Writer
|
||||
}
|
||||
|
||||
func NewRootLogger() *ELog {
|
||||
return NewRootLoggerWithFormat(
|
||||
NewFormat().
|
||||
|
@ -111,6 +113,7 @@ func NewRootLoggerWithFormat(format *LogFormat) *ELog {
|
|||
return &ELog{
|
||||
name: "main",
|
||||
Format: format,
|
||||
Output: os.Stderr,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +164,7 @@ func (e *ELog) _DoLog(level LogLevel, path []string, message string, a ...any) (
|
|||
}
|
||||
tail = tail.Next
|
||||
}
|
||||
return fmt.Println(log.String())
|
||||
return fmt.Fprintln(e.Output, log.String())
|
||||
}
|
||||
|
||||
func (e *ELog) Debug(message string, a ...any) (n int, err error) {
|
||||
|
|
Loading…
Reference in New Issue