Replies: 2 comments 1 reply
-
This just requires a custom logrus.TextFormatter.
Can be done with logrus.JSONFormatter. So However, I think "Attempting to download the image" arch=aarch64 digest="sha256:5ecac6447be66a164626744a87a27fd4e6c6606dc683e0a233870af63df4276a" location="https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-arm64.img" into Attempting to download the image as So maybe just supporting |
Beta Was this translation helpful? Give feedback.
-
I tried this change - it seem to work for start/stop/delete/list. I'll do more testing and send a PR later. --- a/cmd/limactl/main.go
+++ b/cmd/limactl/main.go
@@ -60,6 +60,7 @@ func newApp() *cobra.Command {
DisableAutoGenTag: true,
}
rootCmd.PersistentFlags().String("log-level", "", "Set the logging level [trace, debug, info, warn, error]")
+ rootCmd.PersistentFlags().String("log-format", "", "Set the logging format [text, json] (default text)")
rootCmd.PersistentFlags().Bool("debug", false, "debug mode")
// TODO: "survey" does not support using cygwin terminal on windows yet
rootCmd.PersistentFlags().Bool("tty", isatty.IsTerminal(os.Stdout.Fd()), "Enable TUI interactions such as opening an editor. Defaults to true when stdout is a terminal. Set to false for automation.")
@@ -72,6 +73,18 @@ func newApp() *cobra.Command {
}
logrus.SetLevel(lvl)
}
+
+ logFormat, _ := cmd.Flags().GetString("log-format")
+ switch logFormat {
+ case "json":
+ formatter := new(logrus.JSONFormatter)
+ logrus.StandardLogger().SetFormatter(formatter)
+ case "text", "":
+ // logrus default
+ default:
+ return fmt.Errorf("unsupported log-format: %q", logFormat)
+ }
+
debug, _ := cmd.Flags().GetBool("debug")
if debug {
logrus.SetLevel(logrus.DebugLevel) One issue - the progress breaks the log: #2581 |
Beta Was this translation helpful? Give feedback.
-
Looks like limactl (logrus?) automatically disable timestamps and levels and show only the message, and does not quote " in the message when logging to a terminal, but when redirecting to file we get to much info we don't need in machine unfriendly format, and extra quoting in messages.
Example log when using the terminal:
Same when redirecting to file:
My use case - running limactl from another tool, adding its own timestamps and log levels. Here is example logs from the tool:
The log format I would like to have is:
Or even better, jsonlines format, so I can extract only what I need from the logs:
A program running limactl should be able to control the logs from limactl. Maybe we need a new option like --log-raw to just get the raw messages from limactl, or --log-format=json?
Beta Was this translation helpful? Give feedback.
All reactions