Implement basic error logging

This commit is contained in:
George Lacey 2021-05-04 09:34:55 +01:00
parent c39f9ed250
commit 1d683b1163
5 changed files with 22 additions and 3 deletions

0
src/__init__.py Normal file
View File

View File

@ -1,3 +1,4 @@
from .repo import Repo
from .archive import Archive
from .stats import Stats
from .error import Error

17
src/borg/error.py Normal file
View File

@ -0,0 +1,17 @@
from datetime import datetime
class Error(object):
def __init__(self, error: str, time: datetime):
self.error = error
self.time = time
@classmethod
def from_json(cls, json: dict):
error = json['error']
time = datetime.fromisoformat(json['time'])
return cls(error, time)
@classmethod
def from_sql(cls, sql: list):
pass

View File

@ -1,4 +1,5 @@
from .connection import RepoConn, ArchiveConn, StatsConn, ErrorConn
from datetime import datetime
from pathlib import Path
from src import borg
import json
@ -25,6 +26,7 @@ class BorgDatabase(object):
borg_json = json.loads(borg_output)
except json.JSONDecodeError:
self.handle_borg_error(borg_output)
return
self.process_borg_json(borg_json)
def process_borg_json(self, borg_json: dict):
@ -37,4 +39,5 @@ class BorgDatabase(object):
self.stats_conn.insert(stats, repo_id, archive_id)
def handle_borg_error(self, borg_error: str):
pass
error = borg.Error(borg_error, datetime.now())
self.error_conn.insert(error)

View File

@ -17,8 +17,6 @@ class ErrorConn(DatabaseConnection):
return None, None
def _insert(self, record, repo_id=None, archive_id=None) -> int:
if repo_id is None or archive_id is None:
raise Exception("Repo and archive ids not supplied")
with self.sql_lock:
cursor = self.sql_cursor
statement = f"INSERT INTO {self._sql_table}"\