mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-24 05:31:31 +00:00
log-parser: move the kata-log-parser from the tests repo
to the kata-containers repo under the src/tools/log-parser folder and vendor the modules Fixes: #4100 Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
This commit is contained in:
53
src/tools/log-parser/display_csv.go
Normal file
53
src/tools/log-parser/display_csv.go
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Copyright (c) 2018 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type displayCSV struct {
|
||||
}
|
||||
|
||||
func (d *displayCSV) logEntryToSlice(entry LogEntry) []string {
|
||||
var record []string
|
||||
|
||||
v := reflect.ValueOf(entry)
|
||||
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
field := v.Field(i)
|
||||
|
||||
value := fmt.Sprintf("%v", field.Interface())
|
||||
record = append(record, value)
|
||||
}
|
||||
|
||||
return record
|
||||
}
|
||||
|
||||
func (d *displayCSV) Display(entries *LogEntries, fieldNames []string, file *os.File) error {
|
||||
writer := csv.NewWriter(file)
|
||||
|
||||
// header showing the format of the subsequent records
|
||||
if err := writer.Write(fieldNames); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, entry := range entries.Entries {
|
||||
record := d.logEntryToSlice(entry)
|
||||
|
||||
if err := writer.Write(record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
writer.Flush()
|
||||
|
||||
return writer.Error()
|
||||
}
|
||||
Reference in New Issue
Block a user