1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 16:50:34 +03:00

plugins/edsm: Use logger.trace_if(...)

This also re-introduces commented-out Locations tracking, using
'journal.locations' as it's related to that.
This commit is contained in:
Athanasius 2021-08-13 14:58:04 +01:00
parent 79a2003b53
commit bc9f2cda4b
No known key found for this signature in database
GPG Key ID: AE3E527847057C7D

View File

@ -40,7 +40,6 @@ DISCARDED_EVENTS_SLEEP = 10
# trace-if events # trace-if events
CMDR_EVENTS = 'edsm-cmdr-events' CMDR_EVENTS = 'edsm-cmdr-events'
LOCATION_EVENTS = 'edsm-locations'
class This: class This:
@ -407,14 +406,15 @@ def journal_entry( # noqa: C901, CCR001
return return
this.on_foot = state['OnFoot'] this.on_foot = state['OnFoot']
# if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'):
# logger.trace(f'''{entry["event"]} logger.trace_if(
# Commander: {cmdr} 'journal.locations', f'''{entry["event"]}
# System: {system} Commander: {cmdr}
# Station: {station} System: {system}
# state: {state!r} Station: {station}
# entry: {entry!r}''' state: {state!r}
# ) entry: {entry!r}'''
)
# Always update our system address even if we're not currently the provider for system or station, but dont update # Always update our system address even if we're not currently the provider for system or station, but dont update
# on events that contain "future" data, such as FSDTarget # on events that contain "future" data, such as FSDTarget
if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'): if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'):
@ -519,10 +519,11 @@ def journal_entry( # noqa: C901, CCR001
this.queue.put((cmdr, materials)) this.queue.put((cmdr, materials))
# if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'):
# logger.trace(f'''{entry["event"]} logger.trace_if(
# Queueing: {entry!r}''' 'journal.locations', f'''{entry["event"]}
# ) Queueing: {entry!r}'''
)
logger.trace_if(CMDR_EVENTS, f'"{entry["event"]=}" event, queueing: {cmdr=}') logger.trace_if(CMDR_EVENTS, f'"{entry["event"]=}" event, queueing: {cmdr=}')
this.queue.put((cmdr, entry)) this.queue.put((cmdr, entry))
@ -656,13 +657,15 @@ def worker() -> None: # noqa: CCR001 C901 # Cant be broken up currently
logger.trace_if(CMDR_EVENTS, f'pending contains:\n{chr(0x0A).join(str(p) for p in pending)}') logger.trace_if(CMDR_EVENTS, f'pending contains:\n{chr(0x0A).join(str(p) for p in pending)}')
if any(p for p in pending if p['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked')): if any(p for p in pending if p['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked')):
logger.trace_if(LOCATION_EVENTS, "pending has at least one of " logger.trace_if('journal.locations', "pending has at least one of "
"('CarrierJump', 'FSDJump', 'Location', 'Docked')" "('CarrierJump', 'FSDJump', 'Location', 'Docked')"
" and it passed should_send()") " and it passed should_send()")
for p in pending: for p in pending:
if p['event'] in ('Location'): if p['event'] in ('Location'):
logger.trace_if(LOCATION_EVENTS, '"Location" event in pending passed should_send(), ' logger.trace_if(
f'timestamp: {p["timestamp"]}') 'journal.locations',
f'"Location" event in pending passed should_send(),timestamp: {p["timestamp"]}'
)
creds = credentials(cmdr) # TODO: possibly unbound creds = credentials(cmdr) # TODO: possibly unbound
if creds is None: if creds is None:
@ -683,25 +686,25 @@ def worker() -> None: # noqa: CCR001 C901 # Cant be broken up currently
data_elided = data.copy() data_elided = data.copy()
data_elided['apiKey'] = '<elided>' data_elided['apiKey'] = '<elided>'
logger.trace_if( logger.trace_if(
LOCATION_EVENTS, 'journal.locations',
"pending has at least one of ('CarrierJump', 'FSDJump', 'Location', 'Docked')" "pending has at least one of ('CarrierJump', 'FSDJump', 'Location', 'Docked')"
" Attempting API call with the following events:" " Attempting API call with the following events:"
) )
for p in pending: for p in pending:
logger.trace_if(LOCATION_EVENTS, f"Event: {p!r}") logger.trace_if('journal.locations', f"Event: {p!r}")
if p['event'] in ('Location'): if p['event'] in ('Location'):
logger.trace_if( logger.trace_if(
LOCATION_EVENTS, 'journal.locations',
f'Attempting API call for "Location" event with timestamp: {p["timestamp"]}' f'Attempting API call for "Location" event with timestamp: {p["timestamp"]}'
) )
logger.trace_if( logger.trace_if(
LOCATION_EVENTS, f'Overall POST data (elided) is:\n{json.dumps(data_elided, indent=2)}' 'journal.locations', f'Overall POST data (elided) is:\n{json.dumps(data_elided, indent=2)}'
) )
r = this.session.post(TARGET_URL, data=data, timeout=_TIMEOUT) r = this.session.post(TARGET_URL, data=data, timeout=_TIMEOUT)
# logger.trace(f'API response content: {r.content}') logger.trace_if('plugin.edsm.api', f'API response content: {r.content!r}')
r.raise_for_status() r.raise_for_status()
reply = r.json() reply = r.json()
@ -720,11 +723,11 @@ def worker() -> None: # noqa: CCR001 C901 # Cant be broken up currently
else: else:
if msg_num // 100 == 1: if msg_num // 100 == 1:
# logger.trace('Overall OK') logger.trace_if('plugin.edsm.api', 'Overall OK')
pass pass
elif msg_num // 100 == 5: elif msg_num // 100 == 5:
# logger.trace('Event(s) not currently processed, but saved for later') logger.trace_if('plugin.edsm.api', 'Event(s) not currently processed, but saved for later')
pass pass
else: else: