Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/logcli/output/jsonl.go

34 lines
678 B

package output
import (
"encoding/json"
"log"
"time"
"github.com/grafana/loki/pkg/loghttp"
)
// JSONLOutput prints logs and metadata as JSON Lines, suitable for scripts
type JSONLOutput struct {
options *LogOutputOptions
}
// Format a log entry as json line
func (o *JSONLOutput) Format(ts time.Time, lbls loghttp.LabelSet, maxLabelsLen int, line string) string {
entry := map[string]interface{}{
"timestamp": ts.In(o.options.Timezone),
"line": line,
}
// Labels are optional
if !o.options.NoLabels {
entry["labels"] = lbls
}
out, err := json.Marshal(entry)
if err != nil {
log.Fatalf("error marshalling entry: %s", err)
}
return string(out)
}