MCPcopy
hub / github.com/rs/zerolog / main

Function main

cmd/prettylog/prettylog.go:37–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35}
36
37func main() {
38 timeFormats := map[string]string{
39 "default": time.Kitchen,
40 "full": time.RFC1123,
41 }
42
43 timeFormatFlag := flag.String(
44 "time-format",
45 "default",
46 "Time format, either 'default' or 'full'",
47 )
48
49 flag.Parse()
50
51 timeFormat, ok := timeFormats[*timeFormatFlag]
52 if !ok {
53 panic("Invalid time-format provided")
54 }
55
56 writer := zerolog.NewConsoleWriter()
57 writer.TimeFormat = timeFormat
58
59 if isInputFromPipe() {
60 _ = processInput(os.Stdin, writer)
61 } else if flag.NArg() >= 1 {
62 for _, filename := range flag.Args() {
63 // Scan each line from filename and write it into writer
64 reader, err := os.Open(filename)
65 if err != nil {
66 fmt.Printf("%s open: %v", filename, err)
67 os.Exit(1)
68 }
69
70 if err := processInput(reader, writer); err != nil {
71 fmt.Printf("%s scan: %v", filename, err)
72 os.Exit(1)
73 }
74 }
75 } else {
76 fmt.Println("Usage:")
77 fmt.Println(" app_with_zerolog | 2> >(prettylog)")
78 fmt.Println(" prettylog zerolog_output.jsonl")
79 os.Exit(1)
80 return
81 }
82}

Callers

nothing calls this directly

Calls 6

NewConsoleWriterFunction · 0.92
isInputFromPipeFunction · 0.85
processInputFunction · 0.85
PrintfMethod · 0.80
PrintlnMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected