Closed
Description
When limactl is run by another program, it may wan to show limactl logs in its
own logs. With the current text format, this show duplicate timetamps, log
level, and extra quoting in values (since the format is key="value".
Example usage from another program:
% drenv start envs/vm.yaml -v
2024-09-01 21:49:16,582 INFO [vm] Starting environment
2024-09-01 21:49:16,583 DEBUG [main] Add executor profiles
2024-09-01 21:49:16,584 DEBUG [cluster] Running ('/Users/nsoffer/src/lima/_output/bin/limactl', 'list', '--format', '{{.Name}}')
2024-09-01 21:49:16,603 INFO [cluster] Starting lima cluster
2024-09-01 21:49:16,603 DEBUG [cluster] Running ('/Users/nsoffer/src/lima/_output/bin/limactl', 'list', '--format', '{{.Name}}')
2024-09-01 21:49:16,633 DEBUG [cluster] Running ('/Users/nsoffer/src/lima/_output/bin/limactl', 'create', '--name', 'cluster', '/var/folders/qs/_z10qgxn3gsfw8vmkr9b3s4w0000gn/T/drenv.lima.cluster.tmpe37ne8tn')
2024-09-01 21:49:16,647 DEBUG [cluster] time="2024-09-01T21:49:16+03:00" level=info msg="Terminal is not available, proceeding without opening an editor"
2024-09-01 21:49:16,661 DEBUG [cluster] time="2024-09-01T21:49:16+03:00" level=info msg="Attempting to download the image" arch=aarch64 digest= location="https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
...
Can be fixed by adding a json log format:
```console
% _output/bin/limactl start --vm-type vz --plain --tty=false --log-format json
{"level":"info","msg":"Terminal is not available, proceeding without opening an editor","time":"2024-09-03T00:14:43+03:00"}
{"level":"info","msg":"Starting the instance \"default\" with VM driver \"vz\"","time":"2024-09-03T00:14:43+03:00"}
{"arch":"aarch64","digest":"sha256:5ecac6447be66a164626744a87a27fd4e6c6606dc683e0a233870af63df4276a","level":"info","location":"https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-arm64.img","msg":"Attempting to download the image","time":"2024-09-03T00:14:43+03:00"}
With this the program running limactl can:
- parse the log with standard parsers
- decide which messages to show based message properties
- change its own log level based on limactl message level
- pick which values to log from the json object
This may also help to process logs later for various purposes.
Discussed in in #2576