Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Option log-format=json is ignored for plugin logs #1099

Closed
quality-leftovers opened this issue Mar 19, 2024 · 1 comment · Fixed by #1108
Closed

cli: Option log-format=json is ignored for plugin logs #1099

quality-leftovers opened this issue Mar 19, 2024 · 1 comment · Fixed by #1108
Labels

Comments

@quality-leftovers
Copy link

quality-leftovers commented Mar 19, 2024

Describe the bug
Using -log-format=json does not apply to logging of (hc)plugin

To Reproduce
Steps to reproduce the behavior:

  1. Start tusd using -log-format=json and (hc)plugin hook
  2. Check logs
  3. The logs of the main process are formatted as json, the plugin logs are formatted as plain text

Expected behavior
All logs are formatted as json

Setup details
I tried using both "log" and hc-log in the plugin.

Initializing the logger in the plugin using

hclog.New(&hclog.LoggerOptions{
		Level:      logLevel,
		JSONFormat: true,
	})

does not produce the desired results.

Instead I had to add JSONFormat: true, to

Logger: hclog.New(&hclog.LoggerOptions{
Name: "plugin",
Level: hclog.Debug,
Output: os.Stdout,
TimeFormat: "2006/01/02 03:04:05.000000",

It would be nice to either pass the Json flag to the hclogger instance or if something like an hclog->slog adapter was use d (like https://github.com/evanphx/go-hclog-slog, but in the opposite direction. Not sure if such a package exists / is possible)

Log output "as is"

{"time":"2024-03-19T14:29:53.249651675Z","level":"INFO","msg":"Using '/srv/tusd-data/data' as directory storage."}
{"time":"2024-03-19T14:29:53.250772425Z","level":"INFO","msg":"Using 0.00MB as maximum size."}
{"time":"2024-03-19T14:29:53.250811027Z","level":"INFO","msg":"Using '/usr/local/bin/tusd-hook-plugin' to load plugin for hooks"}
2024/03/19 02:29:53.251028 [DEBUG] plugin: starting plugin: path=/usr/local/bin/tusd-hook-plugin args=["/usr/local/bin/tusd-hook-plugin"]
2024/03/19 02:29:53.251524 [DEBUG] plugin: plugin started: path=/usr/local/bin/tusd-hook-plugin pid=15
2024/03/19 02:29:53.251638 [DEBUG] plugin: waiting for RPC address: plugin=/usr/local/bin/tusd-hook-plugin
2024/03/19 02:29:53.259521 [DEBUG] plugin.tusd-hook-plugin: plugin address: network=unix address=/tmp/plugin1135885035 timestamp=2024-03-19T14:29:53.259Z
2024/03/19 02:29:53.262943 [INFO]  plugin.tusd-hook-plugin: Setup: timestamp=2024-03-19T14:29:53.26
...

Log output using: https://github.com/quality-leftovers/tusd/tree/plugin-log-json

{"time":"2024-03-19T14:13:11.704897099Z","level":"INFO","msg":"Using '/srv/tusd-data/data' as directory storage."}
{"time":"2024-03-19T14:13:11.705671906Z","level":"INFO","msg":"Using 0.00MB as maximum size."}
{"time":"2024-03-19T14:13:11.705711607Z","level":"INFO","msg":"Using '/usr/local/bin/tusd-hook-plugin' to load plugin for hooks"}
{"@level":"debug","@message":"starting plugin","@module":"plugin","@timestamp":"2024/03/19 02:13:11.705805","args":["/usr/local/bin/tusd-hook-plugin"],"path":"/usr/local/bin/tusd-hook-plugin"}
{"@level":"debug","@message":"plugin started","@module":"plugin","@timestamp":"2024/03/19 02:13:11.706353","path":"/usr/local/bin/tusd-hook-plugin","pid":13}
{"@level":"debug","@message":"waiting for RPC address","@module":"plugin","@timestamp":"2024/03/19 02:13:11.706474","plugin":"/usr/local/bin/tusd-hook-plugin"}
{"@level":"debug","@message":"using plugin","@module":"plugin","@timestamp":"2024/03/19 02:13:11.722045","version":1}
{"@level":"debug","@message":"plugin address","@module":"plugin.tusd-hook-plugin","@timestamp":"2024/03/19 02:13:11.722055","address":"/tmp/plugin3216457465","network":"unix","timestamp":"2024-03-19T14:13:11.721Z"}
{"@level":"info","@message":"Setup","@module":"plugin.tusd-hook-plugin","@timestamp":"2024/03/19 02:13:11.728717","timestamp":"2024-03-19T14:13:11.728Z"}
@Acconut
Copy link
Member

Acconut commented Mar 20, 2024

Thank you for reporting this. The easiest solution would be to set hclog.LoggerOptions.JSONFormat = true if the JSON format is specified in the flags. This could be passed in using a new field in the PluginHook struct. Would you be willing to open a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants