syslog verbosity isn't honored when specified #665
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#665
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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
Test borgmatic syslog logging on an interactive console.
Steps to reproduce (if a bug)
I specify --syslog-verbosity 1 on the console and it doesn't log to syslog.
Actual behavior (if a bug)
It seems borgmatic checks if stderr is a TTY or if TERM is equal to dumb. And since neither of those criteria are met, my --syslog-verbosity 1 arg isn't honored.
Expected behavior (if a bug)
I don't believe it should do this. Maybe it should just honor --syslog-verbosity straight up? Thoughts?
Other notes / implementation ideas
Alternatively, perhaps this should be documented in both the CLI usage info and website documentation, as to avoid further confusion?
Environment
borgmatic version:
1.7.4
Use
sudo borgmatic --version
orsudo pip show borgmatic | grep ^Version
borgmatic installation method: Alpine community repository
Borg version:
borg 1.2.2
Use
sudo borg --version
Python version:
Python 3.10.10
Database version (if applicable): N/A
operating system and version:
Thanks for taking the time to file this! I think what you've discovered is an unfortunate (and undocumented) side effect of some intentional behavior. What's going on is that borgmatic detects whether you're at an interactive terminal and, if so, implicitly disables syslog logging. The idea is that if you're running one-off actions like
borgmatic list
,borgmatic mount
, etc., you probably don't want your logs filling up with those actions. Logging is more suited to non-interactive use cases like cron jobs where you're not getting immediate output.That's the theory anyway. It sounds like though you've got a use case for borgmatic logging to syslog even when run interactively. Could you tell me a little about this use case? Is it just that you're testing borgmatic out to make sure that the syslog output meets your needs? Or making sure that a command you'll later put into a cron job will log correctly? Something else?
Some potential solutions:
--syslog-verbosity
is zero. So setting, for instance,--syslog-verbosity 1
would force borgmatic to log to syslog.list
ormount
it gets disabled at an interactive terminal, but forcreate
logging doesn't get disabled.Once I better understand what you're trying to do and why, we can settle on the appropriate solution.
I have two use cases for this:
I'm not using a cron job to create backups because I'm backing up manually with
sudo -s borgmatic ...
. I'm using a backup hard disk that I put in a hot-swap cage, and I only insert it when I actually want to run or access my backups. Admittedly, I haven't had need for a log of thecreate
output here yet, but I figure the ability to log that wouldn't hurt.Recently I wanted to run a
borg check
of my repository. This took much longer than I initially anticipated, and I had to leave my computer running overnight, which I rarely ever do. In the morning I had completely forgotten about it and accidentally turned my computer off instead of on, so I never learned about theborg check
result which at this point very likely had finished. Logging the result would have been useful here.Not the OP, but I'll take it! This is helpful. So what do you think of borgmatic:
--syslog-verbosity 2
to opt into syslog logging on the command-line, from a cron job, or from anywhere else?Seems good to me, but I'm not absolutely certain how syslog output for cronjobs works currently, and how this change might affect users who rely on the current behavior. Currently,
--syslog-verbosity
defaults to 0 which is "default", but from the documentation, I can't quite figure out what "default" is exactly. If the currentborgmatic
version logs cronjob output (or at least errors?) to syslog, then this change might break expected behavior for users?Possibly a more backwards compatible solution:
--syslog-verbosity
to override the given default.Interactive users would now be able to e.g. specify
--syslog-verbosity 2
to enable syslog logging, while cronjob users now be able to e.g. specify--syslog-verbosity -1
if they wanted to opt out of logging for some reason.Thereby the default behavior wouldn't change at all for existing users, but it would now be possible to override the default behavior by specifying the
--syslog-verbosity
option.That would certainly be more backwards-compatible, but I'm actually not too worried about that because: 1. The current default of 0 is actually not that useful as a syslog verbosity, as a user's syslog verbosity expectations are typically higher than what you expect on the command-line, and 2. Almost everyone running borgmatic non-interactively likely already overrides the syslog verbosity anyway, as per these sample cron and systemd command-lines.
So how about this as a riff on your idea?
Yeah, I didn't have a good name for it. (Suggestions welcome!) This level shows output from Borg (e.g. for
list
orinfo
actions), and of course it'll show errors—but not a whole lot else.I recently posted (#749) about the weird experience I had with logging. As far as I'm concerned, the current logging code is broken. As a result, I don't worry about backward compatibility, and what I suggest here could be the moving forward syntax and functionality.
The advantage of these commands is that they specify where you log in and how verbose. Since it is the same command for all logging destinations, there is no need to search for destination-specific logging commands. Because the syntax of the command is different from the original, you can leave the original logging commands in place for a transitional period.
here is an example of the terse form specifying logging.
--log-to stderr=2,syslog=-1,file=/tmp/xxx;3 to specify where to send the log information and what level of verbosity.
a more easily read variant
--log-to stderr,verbosity=2
--log-to stdout,verbosity=1
--log-to syslog,verbosity=3
--log-to file, name =$safetemp,verbosity=2
and to turn off logging
--log-to stdout=none|false|off
Which reminds me, you might want to add something $safetemp as a way of providing a pseudo-constant returning a safe temporary file name. I called it a pseudo-constant because it's the same for the duration of a Borgmatic run. We can talk about that in a different ticket.
Thanks for following up here and writing up a proposal for revised logging flags. However I'm not convinced that these changes are necessary to fix the logging problems, and in general borgmatic's flag style is to explode out values into multiple flags where possible instead of using mini dialects to pack multiple values into single flags. (The one major exception I can think of that is
--override
.)So while I do really appreciate you taking the time to put this together, I don't think I'm going to adopt this proposal now. However I am pretty motivated to fix the current logging brokenness, and I think a big piece of that is likely fixing the implicit logging changes that happen when an interactive terminal is detected vs. not detected. In other words, I think the brokenness is in the underlying semantics—the way the code behind the flags ignores the user's stated preference.
Also a side note: borgmatic (intentionally) logs to both stdout and stderr when console logging is enabled. But you can always redirect the output if that's not what you want.
And yeah, feel free to file the
$safetemp
idea as a separate ticket. That sounds interesting and I'd like to hear more about the use case you have for it.I have implemented a version of this in main and it will be part of the next release! After some further simplification, this is the logic I ended up with:
interactive console. I believe this addresses the original ask in the ticket.
This has been released as part of borgmatic 1.8.3!