From 1c96f0b9f4eff37170fd135cf285435c96ee371d Mon Sep 17 00:00:00 2001 From: Daniel Pupius Date: Mon, 21 Apr 2025 11:56:31 -0700 Subject: [PATCH] Add Logista for JSON log processing - Add .logista.yaml configuration for prettier log output - Add github.com/dpup/logista as a go tool - Update Makefile run target to pipe output through logista - Configure the format to show timestamp, level, and message with colors - Add special formatting for different message types - Display telemetry and position data in readable format - Add table display for remaining structured fields --- .logista.yaml | 39 +++++++++++++++++++++++++++++++++++++++ Makefile | 4 ++-- go.mod | 5 +++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 .logista.yaml diff --git a/.logista.yaml b/.logista.yaml new file mode 100644 index 0000000..389879a --- /dev/null +++ b/.logista.yaml @@ -0,0 +1,39 @@ +# Meshstream Logista Configuration +format: | + {{ $timestamp := .timestamp | date | color "blue" }} + {{ $level := .level | colorByLevel .level | bold }} + {{ $logger := .logger | dim }} + {{ $message := .msg }} + + {{ $timestamp }} {{ $level }} [{{ $logger }}] {{ $message }} + + {{- if .from }} + {{ "From:" | dim }} {{ .from }} {{ "To:" | dim }} {{ .to -}} + {{- if .portNum }} {{ "Type:" | dim }} {{ .portNum | color "magenta" }}{{ end -}} + {{- if .channel }} {{ "Channel:" | dim }} {{ .channel | color "green" }}{{ end -}} + {{- if .gateway }} {{ "Gateway:" | dim }} {{ .gateway | color "yellow" }}{{ end }} + {{- end }} + + {{- if eq .level "error" }} + {{ if .error }}{{ .error | color "red" }}{{ end }} + {{- end }} + + {{- if .message }} + {{ "Message:" | dim }} {{ .message }} + {{- end }} + + {{- if and .latitude .longitude }} + {{ "Position:" | dim }} {{ .latitude }}, {{ .longitude }}{{ if .altitude }} Alt: {{ .altitude }}m{{ end }} + {{- end }} + + {{- if or .temperature .batteryLevel .voltage }} + {{ "Telemetry:" | dim }}{{ if .temperature }} Temp: {{ .temperature }}°C{{ end }}{{ if .batteryLevel }} Battery: {{ .batteryLevel }}%{{ end }}{{ if .voltage }} Voltage: {{ .voltage }}V{{ end }} + {{- end }} + + {{ filter . "timestamp" "level" "logger" "msg" "error" "from" "to" "portNum" "channel" "gateway" "message" "latitude" "longitude" "altitude" "temperature" "batteryLevel" "voltage" | table }} + +# Date formatting +date_format: "15:04:05.000" + +# Handle non-JSON lines +handle_non_json: true \ No newline at end of file diff --git a/Makefile b/Makefile index 8bddafa..aaffdd9 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,9 @@ build: mkdir -p dist go build -o dist/meshstream -# Run the application +# Run the application with json log formatting run: build - ./dist/meshstream + ./dist/meshstream 2>&1 | go tool github.com/dpup/logista # Generate Go code from Protocol Buffers gen-proto: tools diff --git a/go.mod b/go.mod index 6e737b7..4af8d0a 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,11 @@ module meshstream go 1.24.1 +// Add logista as a go tool +toolchain go1.24.1 + +tool github.com/dpup/logista v1.0.7 + require ( github.com/eclipse/paho.mqtt.golang v1.5.0 google.golang.org/protobuf v1.36.6