Skip to content

Commit a25bc47

Browse files
committed
Add logger
1 parent 5607798 commit a25bc47

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

logger/logger.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package logger
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"time"
7+
8+
"github.com/rs/zerolog"
9+
)
10+
11+
func NewLog(logTpye string) (logger zerolog.Logger) {
12+
zerolog.TimeFieldFormat = time.RFC3339
13+
logger = zerolog.New(os.Stdout).With().Timestamp().Str("role", filepath.Base(os.Args[0])).Logger()
14+
15+
if logTpye == "console" {
16+
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339, NoColor: true}
17+
logger = zerolog.New(output).With().Timestamp().Str("role", filepath.Base(os.Args[0])).Logger()
18+
}
19+
20+
return
21+
}

0 commit comments

Comments
 (0)