本文整理汇总了Python中weblate.logger.LOGGER.error方法的典型用法代码示例。如果您正苦于以下问题:Python LOGGER.error方法的具体用法?Python LOGGER.error怎么用?Python LOGGER.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weblate.logger.LOGGER
的用法示例。
在下文中一共展示了LOGGER.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bitbucket_hook_helper
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def bitbucket_hook_helper(data):
"""API to handle service hooks from Bitbucket."""
if 'push' in data:
return bitbucket_webhook_helper(data)
# Parse owner, branch and repository name
owner = data['repository']['owner']
slug = data['repository']['slug']
if data['commits']:
branch = data['commits'][-1]['branch']
else:
branch = None
params = {'owner': owner, 'slug': slug}
# Construct possible repository URLs
if data['repository']['scm'] == 'git':
repos = [repo % params for repo in BITBUCKET_GIT_REPOS]
elif data['repository']['scm'] == 'hg':
repos = [repo % params for repo in BITBUCKET_HG_REPOS]
else:
LOGGER.error(
'unsupported repository: %s',
repr(data['repository'])
)
raise ValueError('unsupported repository')
return {
'service_long_name': 'Bitbucket',
'repo_url': ''.join([
data['canon_url'], data['repository']['absolute_url']
]),
'repos': repos,
'branch': branch,
}
示例2: get_avatar_image
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def get_avatar_image(user, size):
"""
Returns avatar image from cache (if available) or downloads it.
"""
cache_key = 'avatar-img-{0}-{1}'.format(
user.username,
size
)
# Try using avatar specific cache if available
try:
cache = caches['avatar']
except InvalidCacheBackendError:
cache = caches['default']
image = cache.get(cache_key)
if image is None:
try:
image = download_avatar_image(user, size)
cache.set(cache_key, image)
except IOError as error:
report_error(
error, sys.exc_info(),
extra_data={'avatar': user.username}
)
LOGGER.error(
'Failed to fetch avatar for %s: %s',
user.username,
str(error)
)
return get_fallback_avatar(size)
return image
示例3: get_plural_type
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def get_plural_type(base_code, pluralequation):
"""Get correct plural type for language."""
# Remove not needed parenthesis
if pluralequation[-1] == ';':
pluralequation = pluralequation[:-1]
# No plural
if pluralequation == '0':
return data.PLURAL_NONE
# Standard plural equations
for mapping in data.PLURAL_MAPPINGS:
if pluralequation in mapping[0]:
return mapping[1]
# Arabic special case
if base_code in ('ar',):
return data.PLURAL_ARABIC
# Log error in case of uknown mapping
LOGGER.error(
'Can not guess type of plural for %s: %s', base_code, pluralequation
)
return data.PLURAL_UNKNOWN
示例4: get_plural_type
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def get_plural_type(code, pluralequation):
'''
Gets correct plural type for language.
'''
# Remove not needed parenthesis
if pluralequation[-1] == ';':
pluralequation = pluralequation[:-1]
if pluralequation[0] == '(' and pluralequation[-1] == ')':
pluralequation = pluralequation[1:-1]
# Get base language code
base_code = code.replace('_', '-').split('-')[0]
# No plural
if pluralequation == '0':
return data.PLURAL_NONE
# Standard plural equations
for mapping in data.PLURAL_MAPPINGS:
if pluralequation in mapping[0]:
return mapping[1]
# Arabic special case
if base_code in ('ar',):
return data.PLURAL_ARABIC
# Log error in case of uknown mapping
LOGGER.error(
'Can not guess type of plural for %s: %s', code, pluralequation
)
return data.PLURAL_UNKNOWN
示例5: get_avatar_image
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def get_avatar_image(request, user, size):
"""Return avatar image from cache (if available) or download it."""
cache_key = '-'.join((
'avatar-img',
user.username,
str(size)
))
# Try using avatar specific cache if available
try:
cache = caches['avatar']
except InvalidCacheBackendError:
cache = caches['default']
image = cache.get(cache_key)
if image is None:
try:
image = download_avatar_image(user, size)
cache.set(cache_key, image)
except (IOError, CertificateError) as error:
report_error(
error, sys.exc_info(), request,
extra_data={'avatar': user.username},
level='debug',
)
LOGGER.error(
'Failed to fetch avatar for %s: %s',
user.username,
str(error)
)
return get_fallback_avatar(size)
return image
示例6: mail_admins_contact
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def mail_admins_contact(request, subject, message, context, sender, to):
"""Send a message to the admins, as defined by the ADMINS setting."""
LOGGER.info(
'contact form from %s',
sender,
)
if not to and settings.ADMINS:
to = [a[1] for a in settings.ADMINS]
elif not settings.ADMINS:
messages.error(
request,
_('Message could not be sent to administrator!')
)
LOGGER.error(
'ADMINS not configured, can not send message!'
)
return
mail = EmailMultiAlternatives(
'{0}{1}'.format(settings.EMAIL_SUBJECT_PREFIX, subject % context),
message % context,
to=to,
headers={'Reply-To': sender},
)
mail.send(fail_silently=False)
messages.success(
request,
_('Message has been sent to administrator.')
)
示例7: report_error
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def report_error(self, exc, request, message):
"""Wrapper for handling error situations"""
extra = {'mt_url': self.request_url, 'mt_params': self.request_params}
report_error(exc, request, extra, prefix='Machine translation error')
LOGGER.error(message, self.name)
LOGGER.info(
'Last URL: %s, params: %s', extra['mt_url'], extra['mt_params']
)
示例8: send_mails
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def send_mails(mails):
"""Sends multiple mails in single connection."""
try:
connection = get_connection()
connection.send_messages(mails)
except SMTPException as error:
LOGGER.error('Failed to send email: %s', error)
report_error(error, sys.exc_info())
示例9: report_error
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def report_error(error, exc_info, request=None, extra_data=None):
"""Wrapper for error reporting
This can be used for store exceptions in error reporting solutions as
rollbar while handling error gracefully and giving user cleaner message.
"""
if HAS_ROLLBAR and hasattr(settings, 'ROLLBAR'):
rollbar.report_exc_info(exc_info, request, extra_data=extra_data)
LOGGER.error(
'Handled exception %s: %s',
error.__class__.__name__,
str(error)
)
示例10: report_error
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def report_error(self, exc, message):
"""Wrapper for handling error situations"""
report_error(
exc, sys.exc_info(),
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
LOGGER.error(
message,
self.name,
)
LOGGER.error(
'Last fetched URL: %s, params: %s',
self.request_url,
self.request_params,
)
示例11: report_error
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def report_error(error, exc_info, request=None, extra_data=None):
"""Wrapper for error reporting
This can be used for store exceptions in error reporting solutions as
rollbar while handling error gracefully and giving user cleaner message.
"""
if HAS_ROLLBAR and hasattr(settings, 'ROLLBAR'):
rollbar.report_exc_info(exc_info, request, extra_data=extra_data)
LOGGER.error(
'Handled exception %s: %s',
error.__class__.__name__,
force_text(error).encode('utf-8')
)
# Print error when running testsuite
if sys.argv[1:2] == ['test']:
traceback.print_exc()
示例12: clean_checksum
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def clean_checksum(self):
"""Validate whether checksum is valid and fetches unit for it."""
if 'checksum' not in self.cleaned_data:
return
unit_set = self.translation.unit_set
try:
self.cleaned_data['unit'] = unit_set.filter(
id_hash=self.cleaned_data['checksum']
)[0]
except (Unit.DoesNotExist, IndexError):
LOGGER.error(
'string %s disappeared!', self.cleaned_data['checksum']
)
raise ValidationError(_(
'The string you wanted to translate is no longer available!'
))
示例13: translate
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def translate(self, language, text, unit, user):
'''
Returns list of machine translations.
'''
language = self.convert_language(language)
if text == '':
return []
if not self.is_supported(language):
return []
try:
translations = self.download_translations(
language, text, unit, user
)
return [
{
'text': trans[0],
'quality': trans[1],
'service': trans[2],
'source': trans[3]
}
for trans in translations
]
except Exception as exc:
report_error(
exc, sys.exc_info(),
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
LOGGER.error(
'Failed to fetch translations from %s',
self.name,
)
LOGGER.error(
'Last fetched URL: %s, params: %s',
self.request_url,
self.request_params,
)
raise MachineTranslationError('{}: {}'.format(
exc.__class__.__name__,
str(exc)
))
示例14: mail_admins_contact
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def mail_admins_contact(request, subject, message, context, sender):
"""
Sends a message to the admins, as defined by the ADMINS setting.
"""
LOGGER.info("contact form from %s", sender)
if not settings.ADMINS:
messages.error(request, _("Message could not be sent to administrator!"))
LOGGER.error("ADMINS not configured, can not send message!")
return
mail = EmailMultiAlternatives(
"%s%s" % (settings.EMAIL_SUBJECT_PREFIX, subject % context),
message % context,
to=[a[1] for a in settings.ADMINS],
headers={"Reply-To": sender},
)
mail.send(fail_silently=False)
messages.success(request, _("Message has been sent to administrator."))
示例15: clean_checksum
# 需要导入模块: from weblate.logger import LOGGER [as 别名]
# 或者: from weblate.logger.LOGGER import error [as 别名]
def clean_checksum(self):
'''
Validates whether checksum is valid and fetches unit for it.
'''
if 'checksum' not in self.cleaned_data:
return
unit_set = self.translation.unit_set
try:
self.cleaned_data['unit'] = unit_set.filter(
checksum=self.cleaned_data['checksum'],
)[0]
except (Unit.DoesNotExist, IndexError):
LOGGER.error(
'message %s disappeared!',
self.cleaned_data['checksum']
)
raise ValidationError(
_('Message you wanted to translate is no longer available!')
)