Skip to content

Commit

Permalink
noop, logging.* => logger.*
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Sep 7, 2023
1 parent 44f4262 commit 3eaaa3e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def check_token(self, load_source=True):
"""
token = request.values['token']
domains = Domain.query(Domain.tokens == token).fetch()
logging.info(f'Found domains for token {token}: {domains}')
logger.info(f'Found domains for token {token}: {domains}')
if not domains:
self.error(f'No domains found for token {token}. Click Reconnect to Bridgy above to register your domain!', 403)

Expand Down
2 changes: 1 addition & 1 deletion cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def dispatch_request(self):
try:
actor = source.gr_source.get_actor(user_id)
except BaseException as e:
logging.debug('Failed', exc_info=True)
logger.debug('Failed', exc_info=True)
# Mastodon API returns HTTP 404 for deleted (etc) users, and
# often one or more users' Mastodon instances are down.
code, _ = util.interpret_http_exception(e)
Expand Down
6 changes: 3 additions & 3 deletions micropub.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def load_source(self):
self.error('unauthorized', 'No publish user found with that token', status=401)

def dispatch_request(self):
logging.info(f'Params: {list(request.values.items())}')
logger.info(f'Params: {list(request.values.items())}')

# auth
self.source = self.load_source()
Expand Down Expand Up @@ -132,7 +132,7 @@ def dispatch_request(self):
if action not in ('create', 'delete'):
self.error('not_implemented', f'Action {action} not supported')

logging.debug(f'Got microformats2: {json_dumps(mf2, indent=2)}')
logger.debug(f'Got microformats2: {json_dumps(mf2, indent=2)}')
try:
obj = microformats2.json_to_object(mf2)
except (TypeError, ValueError) as e:
Expand All @@ -142,7 +142,7 @@ def dispatch_request(self):
# Mastodon to use content, not displayName
if obj.get('objectType') == 'article':
obj['objectType'] = 'note'
logging.debug(f'Converted to ActivityStreams object: {json_dumps(obj, indent=2)}')
logger.debug(f'Converted to ActivityStreams object: {json_dumps(obj, indent=2)}')

canonicalized = self.source.URL_CANONICALIZER(url or '') or ''
post_id = self.source.gr_source.post_id(canonicalized)
Expand Down
4 changes: 2 additions & 2 deletions original_post_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def discover(source, activity, fetch_hfeed=True, include_redirect_sources=True,
mentions.update(att_origs)

if len(originals) > MAX_ORIGINAL_CANDIDATES:
logging.info(f'{len(originals)} originals, pruning down to {MAX_ORIGINAL_CANDIDATES}')
logger.info(f'{len(originals)} originals, pruning down to {MAX_ORIGINAL_CANDIDATES}')
originals = sorted(originals)[:MAX_ORIGINAL_CANDIDATES]
if len(mentions) > MAX_MENTION_CANDIDATES:
logging.info(f'{len(mentions)} mentions, pruning down to {MAX_MENTION_CANDIDATES}')
logger.info(f'{len(mentions)} mentions, pruning down to {MAX_MENTION_CANDIDATES}')
mentions = sorted(mentions)[:MAX_MENTION_CANDIDATES]

def resolve(urls):
Expand Down
38 changes: 19 additions & 19 deletions publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def maybe_inject_silo_content(self, item):

def _run(self):
"""Returns CreationResult on success, None otherwise."""
logging.info(f'Params: {list(request.values.items())}')
logger.info(f'Params: {list(request.values.items())}')
assert self.PREVIEW in (True, False)

# parse and validate target URL
Expand Down Expand Up @@ -253,7 +253,7 @@ def _run(self):
for embedded in ('rsvp', 'invitee', 'repost-of', 'like-of', 'in-reply-to'):
if embedded in item.get('properties', []):
item_types.add(embedded)
logging.info(
logger.info(
'Object type(s) %s not supported; error=%s; trying next.',
item_types, result.error_plain)
types = types.union(item_types)
Expand All @@ -266,7 +266,7 @@ def _run(self):
if code in self.source.DISABLE_HTTP_CODES or isinstance(e, models.DisableSource):
# the user deauthorized the bridgy app, or the token expired, so
# disable this source.
logging.warning(f'Disabling source due to: {e}', exc_info=True)
logger.warning(f'Disabling source due to: {e}', exc_info=True)
self.source.status = 'disabled'
self.source.put()
if isinstance(e, (NotImplementedError, ValueError, urllib.error.URLError)):
Expand Down Expand Up @@ -318,7 +318,7 @@ def _find_source(self, source_cls, url, domain):
sources_ready = []
best_match = None
for source in sources:
logging.info(f'Source: {source.bridgy_url()} , features {source.features}, status {source.status}, poll status {source.poll_status}')
logger.info(f'Source: {source.bridgy_url()} , features {source.features}, status {source.status}, poll status {source.poll_status}')
if source.status != 'disabled' and 'publish' in source.features:
# use a source that has a domain_url matching the url provided,
# including path. find the source with the closest match.
Expand Down Expand Up @@ -370,7 +370,7 @@ def attempt_single_item(self, item):
obj['url'] = self.source_url()
elif 'url' not in obj:
obj['url'] = self.fetched.url
logging.debug(f'Converted to ActivityStreams object: {json_dumps(obj, indent=2)}')
logger.debug(f'Converted to ActivityStreams object: {json_dumps(obj, indent=2)}')

# posts and comments need content
obj_type = obj.get('objectType')
Expand Down Expand Up @@ -410,7 +410,7 @@ def attempt_single_item(self, item):
self.entity.type = self.entity.published.get('type') or models.get_type(obj)

ret = json_dumps(self.entity.published, indent=2)
logging.info(f'Returning {ret}')
logger.info(f'Returning {ret}')
return gr_source.creation_result(ret)

def delete(self, source_url):
Expand Down Expand Up @@ -442,16 +442,16 @@ def delete(self, source_url):
except NotImplementedError:
return self.error(f"Sorry, deleting isn't supported for {self.source.gr_source.NAME} yet")

logging.info(f'Deleting silo post id {id}')
logger.info(f'Deleting silo post id {id}')
self.entity = models.Publish(parent=self.entity.key.parent(),
source=self.source.key, type='delete')
self.entity.put()
logging.debug(f"Publish entity for delete: {self.entity.key.urlsafe().decode()}")
logger.debug(f"Publish entity for delete: {self.entity.key.urlsafe().decode()}")

resp = self.source.gr_source.delete(id)
resp.content.setdefault('id', id)
resp.content.setdefault('url', url)
logging.info(resp.content)
logger.info(resp.content)
self.entity.published = resp.content
self.entity.status = 'deleted'
self.entity.put()
Expand Down Expand Up @@ -499,7 +499,7 @@ def expand_target_urls(self, activity):
if not ok:
continue

logging.debug(f'expand_target_urls fetching field={field}, url={url}')
logger.debug(f'expand_target_urls fetching field={field}, url={url}')
try:
mf2 = util.fetch_mf2(url)
except AssertionError:
Expand All @@ -509,7 +509,7 @@ def expand_target_urls(self, activity):
raise
except BaseException:
# it's not a big deal if we can't fetch an in-reply-to url
logging.info(f'expand_target_urls could not fetch field={field}, url={url}', exc_info=True)
logger.info(f'expand_target_urls could not fetch field={field}, url={url}', exc_info=True)
continue

synd_urls = mf2['rels'].get('syndication', [])
Expand All @@ -527,7 +527,7 @@ def expand_target_urls(self, activity):
synd_urls += microformats2.get_string_urls(
item.get('properties', {}).get('syndication', []))

logging.debug(f'expand_target_urls found rel=syndication for url={url} : {synd_urls!r}')
logger.debug(f'expand_target_urls found rel=syndication for url={url} : {synd_urls!r}')
augmented += synd_urls

if augmented:
Expand All @@ -549,7 +549,7 @@ def get_or_add_publish_entity(self, source_url):
except Exception as e:
code = getattr(e, 'code', None)
details = getattr(e, 'details', None)
logging.info((code and code(), details and details()))
logger.info((code and code(), details and details()))
if (code and code() == grpc.StatusCode.ABORTED and
details and 'too much contention' in details()):
return self.error("You're already publishing that post in another request.",
Expand All @@ -566,7 +566,7 @@ def _get_or_add_publish_entity(self, source_url):
Publish.status == 'new', Publish.type != 'preview',
Publish.source == self.source.key, ancestor=page.key).get()
if pending:
logging.warning(f'Collided with publish: {pending.key.urlsafe().decode()}')
logger.warning(f'Collided with publish: {pending.key.urlsafe().decode()}')
raise CollisionError()

entity = Publish.query(
Expand All @@ -578,7 +578,7 @@ def _get_or_add_publish_entity(self, source_url):
entity.type = 'preview'
entity.put()

logging.debug(f"Publish entity: {entity.key.urlsafe().decode()}")
logger.debug(f"Publish entity: {entity.key.urlsafe().decode()}")
return entity

def _render_preview(self, result, include_link=False):
Expand All @@ -604,7 +604,7 @@ def _render_preview(self, result, include_link=False):
'state': util.encode_oauth_state(state),
**state,
}
logging.info(f'Rendering preview with template vars {pprint.pformat(vars)}')
logger.info(f'Rendering preview with template vars {pprint.pformat(vars)}')
return gr_source.creation_result(render_template('preview.html', **vars))


Expand Down Expand Up @@ -638,7 +638,7 @@ def include_link(self, item):

def error(self, error, html=None, status=400, data=None, report=False, **kwargs):
error = html or util.linkify(error)
logging.info(f'publish: {error}')
logger.info(f'publish: {error}')
if report:
self.report_error(error, status=status)
flask_util.error(error, status=status)
Expand Down Expand Up @@ -691,7 +691,7 @@ def include_link(self, item):
return self.state['include_link']

def error(self, error, html=None, status=400, data=None, report=False, **kwargs):
logging.info(f'publish: {error}')
logger.info(f'publish: {error}')
error = html or util.linkify(error)
flash(f'{error}')
if report:
Expand Down Expand Up @@ -746,7 +746,7 @@ def authorize(self):
return False

def error(self, error, **kwargs):
logging.info(f'publish: {error}')
logger.info(f'publish: {error}')
return super().error(error, **kwargs)


Expand Down
2 changes: 1 addition & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def maybe_add_or_delete_source(source_cls, auth_entity, state, **kwargs):
def maybe_disable_original():
orig = source_cls.get_by_id(source.username)
if orig:
logging.info(f'Disabling {orig.bridgy_url()} for lower case {source.bridgy_url()}')
logger.info(f'Disabling {orig.bridgy_url()} for lower case {source.bridgy_url()}')
orig.features = []
orig.put()

Expand Down

0 comments on commit 3eaaa3e

Please sign in to comment.