With --log-json, format borgmatic logs as JSON, not just Borg logs #858
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
Trying to push logs to Graylog via JSON.
Steps to reproduce
borgmatic --log-json info --repo usbdisk
Actual behavior
Outputs "normal" text, instead of JSON.
Expected behavior
Log messages in JSON format.
Other notes / implementation ideas
If you run the same with
-v 2
, amongst normal text output, you can seeborg
's JSON output.borgmatic version
1.8.8
borgmatic installation method
pipx
Borg version
borg 1.2.7
Python version
Python 3.11.2
Database version (if applicable)
No response
Operating system and version
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
Thanks for filing this! However I'm pretty sure the behavior you're seeing is a Borg limitation, even without using borgmatic. For instance, here's the equivalent Borg command to using borgmatic's
--verbosity 2
:(The
--glob-archives
value may vary based on your configuration, andyourrepo
will depend on the path to your Borg repository.)What that command produces is "normal" non-JSON repository information, I guess because Borg doesn't consider its
info
output as log entries subject to--log-json
. And there are no other log entries to display (as JSON) at that verbosity level.But if you add
--debug
, that's the equivalent to borgmatic's--verbosity 2
:That produces the mixed output you're observing:
--log-json
currently only applies to Borg logging and not borgmatic's own logs.--log-json
to them.info
output shows as "normal" text, because again, Borg doesn't consider that as part of its log entries.However, switching back to borgmatic, what you can do is is add the
--json
flag to--log-json
but don't use--verbosity 2
. Here's what that does:--verbosity 2
.--log-json
to them.info
output shows as JSON, because of the--json
flag.Maybe that's more along the lines of what you're looking for?
Thanks for responding @witten. Excellent clarification, thanks heaps. You're right, your final suggestion does the job, but I've now realised it's basically only a summary (without
--progress
of course), and I was barking up the wrong tree.I think I'd like to see borgmatic's logs turned into a structure, moreso than borg. borg JSON is essentially for GUI authors, and mostly resolves therefore around progress, not full state.
I'll give you a couple of my use cases/wishes for this:
What I mean by repo/backup name is each item listed in the borgmatic
repositories:
key (preferably even by borgmatic's label!)I guess the above suggested run method gives some of that, we then miss out on also doing the "human" logging in the same run. One can then do an
info
with JSON after, but that feels clunky.As I type this, perhaps it even belongs in the hooks framework.
Using just
--json
, I do see some useful stuff:... but again, it'd be nice to push that into Graylog, but also see the usual multiline logging (and even push that somewhere, which I'm currently doing to Graylog).
Seeing borgmatic informational stuff, also structured (probably just a "message" field), would also be useful, so that the structured logging is complete.
On top of all of this then would be wrapping it all in GELF.
I dunno, a lot of random spitballing here; I just struggle to keep an eye on backups when viewing the normal logging, and trying to think of better ways.
(I apologize for the delay in getting back to this.) My take is that it's a reasonable ask for borgmatic logs to (optionally) be in JSON format themselves.. especially since Borg sorta kinds supports JSON logging. I could see automatically keying that off of the existing
--log-json
flag. And starting with just amessage
field would be the easiest way to get going, although I could imagine adding more fields later on (configuration_file
,repository_path
, etc.). However the one caveat would be that these additional fields to search for would only be in borgmatic's own log entries and not in any associated Borg JSON logs—unless borgmatic injected them there.log-json seems to do nothing except in debug modeto With --log-json, format borgmatic logs as JSON, not just Borg logs