wakatime / wakatime-cli

Command line interface used by all WakaTime text editor plugins
https://wakatime.com/plugins
BSD 3-Clause "New" or "Revised" License
262 stars 40 forks source link

Reorder fields in log file #346

Closed gandarez closed 10 months ago

gandarez commented 3 years ago

Marshaling in Golang produces fields in alphabetical order which is not the ideal in this scenario. The outputted log might follow the legacy implementantion.

https://golang.org/pkg/encoding/json/#Marshal

legacy

{"now": "2021/05/04 09:23:29 -0300", "version": "13.1.0", "plugin": "vscode/1.55.2 vscode-wakatime/5.0.1", "time": 1620131008.961499, "caller": "/Users/gandarez/.vscode/extensions/wakatime.vscode-wakatime-5.0.1/wakatime-master/wakatime/api.py", "lineno": 56, "is_write": true, "file": "/Users/gandarez/Development/go/src/github.com/wakatime/wakatime-cli/pkg/heartbeat/language.go", "level": "DEBUG", "message": "Sending heartbeats to api at https://api.wakatime.com/api/v1/users/current/heartbeats.bulk"}

current

{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/pkg/api/heartbeat.go:26","func":"Send","level":"debug","message":"sending 1 heartbeat(s) to api at https://api.wakatime.com/api/v1/users/current/heartbeats.bulk","now":"2021-05-04T09:40:27-03:00","version":"v0.9.0-alpha.1"}
dron22 commented 3 years ago

The json format for logs is used, as it is machine-readable. Now this issue is about having human-readability and machine-readability at the same time. This makes things more complicated, as it conflicts with the JSON rfc (https://greenbytes.de/tech/webdav/rfc8259.html):

An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.

An array is an ordered sequence of zero or more values.

We won't be able to achieve this behavior, if we stick to logrus. And even if we ditch logrus, it will only be possible with some custom logic using reflect package.

dron22 commented 3 years ago

Will move this to the backlog, as it needs further discussion about the effort/value of it.

alanhamlett commented 10 months ago

Not worth changing as logs are readable enough as-is.