mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-11-01 09:17:08 +00:00
Write log entries as json
Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -13,6 +15,16 @@ const (
|
||||
logDumpFollow
|
||||
)
|
||||
|
||||
type LogEntry struct {
|
||||
Time time.Time `json:"time"`
|
||||
Source string `json:"source"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
func (msg *LogEntry) String() string {
|
||||
return fmt.Sprintf("%s;%s;%s", msg.Time.Format(time.RFC3339Nano), strings.ReplaceAll(msg.Source, `;`, `\;`), msg.Msg)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
|
||||
@@ -49,7 +61,13 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
r := bufio.NewReader(conn)
|
||||
r.WriteTo(os.Stdout)
|
||||
var entry LogEntry
|
||||
decoder := json.NewDecoder(conn)
|
||||
for {
|
||||
if err := decoder.Decode(&entry); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(entry.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user