added logging

This commit is contained in:
John Lancaster
2024-05-27 01:28:38 -05:00
parent 9248162bf7
commit 100720afda

View File

@@ -1,6 +1,9 @@
import json
import logging
import subprocess import subprocess
import click import click
from rich.logging import RichHandler
from restic.console import logger from restic.console import logger
from restic.loki import send_to_loki from restic.loki import send_to_loki
@@ -10,7 +13,8 @@ def get_size(loki_url: str = None):
cmd = ['restic', 'stats', '--mode', 'raw-data', '--json'] cmd = ['restic', 'stats', '--mode', 'raw-data', '--json']
result = subprocess.run(cmd, capture_output=True, text=True) result = subprocess.run(cmd, capture_output=True, text=True)
logger.info(result.stdout) data = json.loads(result.stdout)
logger.info(f'Total size: {data["total_size"] / 10**6:.2f} MB, {data["snapshots_count"]} snapshots')
if loki_url is not None: if loki_url is not None:
send_to_loki(loki_url, result.stdout, backup='size') send_to_loki(loki_url, result.stdout, backup='size')
@@ -23,4 +27,14 @@ def main(loki_url: str = None):
if __name__ == '__main__': if __name__ == '__main__':
import logging
from rich.logging import RichHandler
from restic.console import console
logging.basicConfig(
level='DEBUG', format='%(message)s', handlers=[RichHandler(markup=True, console=console)]
)
main() main()