Skip to content

Commit

Permalink
[app][fix] logging only with levels
Browse files Browse the repository at this point in the history
  • Loading branch information
M3ssman committed Sep 3, 2024
1 parent 94957e6 commit 0628708
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digiflow"
version = "5.2.5"
version = "5.2.6"
description = "Father's Little Digitization Workflow Helper"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
6 changes: 4 additions & 2 deletions src/digiflow/record/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
Datetime,
)
from .record_service import (
Client, HandlerInformation,
RecordsExhaustedException, RecordsServiceException,
Client, HandlerInformation,
RecordRequestHandler,
RecordsExhaustedException,
RecordsServiceException,
run_server
)
13 changes: 4 additions & 9 deletions src/digiflow/record/record_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def save_record_state(self, identifier, state=None, **kwargs):
# read datasets
if not state:
state = self.mark['lock']
if identifier in self.index.keys():
if identifier in self.index:
(idx_raw, idx_data) = self.index[identifier]
dict_row = self.data[idx_data]
right_now = time.strftime(df_r.STATETIME_FORMAT)
Expand All @@ -179,9 +179,7 @@ def save_record_state(self, identifier, state=None, **kwargs):

# if not existing_id:
else:
raise RuntimeError(
'No Record for {} in {}! Cannot save state!'
.format(identifier, self.data_path))
raise RuntimeError(f'No Record for {identifier} in {self.data_path}! Cant save state!')

# store actual state
self._save_file()
Expand Down Expand Up @@ -257,12 +255,9 @@ def frame(self, start, frame_size=1000, mark_state=RECORD_STATE_MASK_FRAME,
if sort_by in self.header:
the_rows = sorted(the_rows, key=lambda r: r[sort_by])
else:
raise RuntimeError("invalid sort by {}! only {} permitted!".format(
sort_by, self.header
))
raise RuntimeError(f"invalid sort by {sort_by}! only {self.header} permitted!")

file_name_out = "{}_{:02d}_{:02d}.{}".format(
file_name, org_start, end_frame, file_ext)
file_name_out = f"{file_name}_{org_start:02d}_{end_frame:02d}.{file_ext}"
path_out = os.path.join(path_dir, file_name_out)
with open(path_out, 'w', encoding='UTF-8') as writer:
csv_writer = csv.DictWriter(
Expand Down
14 changes: 8 additions & 6 deletions src/digiflow/record/record_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def log_request(self, _):
def do_POST(self):
"""handle POST request"""
client_name = self.address_string()
self.log('url path %s from %s', self.path, client_name)
self.log('url path %s from %s', self.path, client_name,
level=logging.INFO)
command, file_name = self._parse_request_path()
if command is None:
return
Expand Down Expand Up @@ -227,8 +228,7 @@ def get_record(self, get_record_state, set_record_state):
response = requests.get(f'{self.oai_server_url}/next',
timeout=self.timeout_secs, headers=the_headers)
except requests.exceptions.RequestException as err:
if self._logger is not None:
self._logger.error("Connection failure: %s", err)
self.log("Connection failure: %s", err, level=logging.ERROR)
raise RecordsServiceException(f"Connection failure: {err}") from err
status = response.status_code
result = response.content
Expand All @@ -239,7 +239,7 @@ def get_record(self, get_record_state, set_record_state):

if status != 200:
self.log("server connection status: %s -> %s", status, result,
logging.ERROR)
level=logging.ERROR)
raise RecordsServiceException(f"Record service error {status} - {result}")

# otherwise response ok
Expand All @@ -248,7 +248,8 @@ def get_record(self, get_record_state, set_record_state):

def update(self, status, oai_urn, **kwargs):
"""Store status update && send message to OAI Service"""
self.log("set status '%s' for urn '%s'", status, oai_urn, logging.DEBUG)
self.log("set status '%s' for urn '%s'", status, oai_urn,
level=logging.DEBUG)
self.record = df_r.Record(oai_urn)
self.record.state = status
# if we have to report somethin' new, then append it
Expand All @@ -260,7 +261,8 @@ def update(self, status, oai_urn, **kwargs):
self.record.identifier,
attr_err.args[0],
self.record.info, kwargs)
self.log("update record %s url %s", self.record, self.oai_server_url, logging.DEBUG)
self.log("update record %s url %s", self.record, self.oai_server_url,
level=logging.DEBUG)
return requests.post(f'{self.oai_server_url}/update', json=self.record.dict(), timeout=60)


Expand Down

0 comments on commit 0628708

Please sign in to comment.