creativeprojects / resticprofile

Configuration profiles manager and scheduler for restic backup
https://creativeprojects.github.io/resticprofile/
GNU General Public License v3.0
604 stars 29 forks source link

log: allow controlling command output redirection #343

Closed jkellerer closed 3 months ago

jkellerer commented 4 months ago

This PR is a super-light version of outstanding PR #207 to control when command output is sent to logs, console or both, with a default of "auto" so that interactive usage isn't fully silent when log is specified (e.g. in global settings).

root@log:/# ./resticprofile --log=test.log containers.check
using temporary cache in /tmp/restic-check-cache-3409750633
create exclusive lock for repository
load indexes
check all packs
check snapshots, trees and blobs
[3:13] 100.00%  580 / 580 snapshots

no errors were found
root@log:/# cat test.log 
2024/03/16 22:12:12 INFO  using configuration file: /etc/resticprofile/profiles.yaml
2024/03/16 22:12:12 INFO  profile 'containers': initializing repository (if not existing)
2024/03/16 22:12:12 INFO  profile 'containers': starting 'check'
using temporary cache in /tmp/restic-check-cache-3409750633
create exclusive lock for repository
load indexes
check all packs
check snapshots, trees and blobs
[3:13] 100.00%  580 / 580 snapshots

no errors were found

.. PR #207 is still required to have proper terminal output in this case but it is better than none.

jkellerer commented 4 months ago

@creativeprojects, let me know what you think about this and whether names need to be adjusted.

creativeprojects commented 4 months ago

Yes, this is a very good idea.

I'm not too sure about the name of the flag either. We could also do:

🤔

jkellerer commented 4 months ago

name was also one thing were I wasn't sure yet. Had used log-commands from default-command.

Maybe add-output-to (e.g. --add-output-to=log, --add-output-to=console, --add-output-to=all)

Mostly the flag wont be needed as the auto value should be fine. Also we have some commands where the output must not be sent to logs. It may be good to have a name that doesn't get in the way if output cannot be added.

jkellerer commented 3 months ago

Changed the name to "command-output", kind of a combination of yours and mine proposals :)

resticprofile --log=rp.log --command-output=log ...
resticprofile --log=rp.log --command-output=console ...
resticprofile --log=rp.log --command-output=all ...
resticprofile --log=rp.log --command-output=auto ...

# also valid
resticprofile --log=rp.log --command-output=log,console ... 
codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 92.85714% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 71.07%. Comparing base (667180e) to head (4061506). Report is 1 commits behind head on master.

Files Patch % Lines
commands.go 0.00% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #343 +/- ## ========================================== + Coverage 71.03% 71.07% +0.05% ========================================== Files 121 121 Lines 12378 12394 +16 ========================================== + Hits 8792 8809 +17 + Misses 3190 3189 -1 Partials 396 396 ``` | [Flag](https://app.codecov.io/gh/creativeprojects/resticprofile/pull/343/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fred) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/creativeprojects/resticprofile/pull/343/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fred) | `71.07% <92.86%> (+0.05%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fred#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.