Commit 4f7cb78f authored by Michal Čihař's avatar Michal Čihař

Move logging handling to separate module

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 2e56df89
......@@ -21,7 +21,6 @@
import os
import re
from copy import _EmptyClass
import logging
import django.utils.translation.trans_real as django_trans
from weblate.requirements import (
check_requirements, get_versions, get_optional_versions
......@@ -30,8 +29,6 @@ from weblate.trans.vcs import GitRepository, RepositoryException
from weblate.trans.data import check_data_writable
from weblate.trans.ssh import create_ssh_wrapper
logger = logging.getLogger('weblate')
def get_root_dir():
'''
......
......@@ -30,7 +30,8 @@ from django.utils.translation import pgettext
from django.core.urlresolvers import reverse
from django.conf import settings
import weblate
from weblate import USER_AGENT
from weblate.logger import LOGGER
from weblate import appsettings
from weblate.trans.util import report_error
......@@ -136,7 +137,7 @@ def get_avatar_image(user, size):
error, sys.exc_info(),
extra_data={'avatar': user.username}
)
weblate.logger.error(
LOGGER.error(
'Failed to fetch avatar for %s: %s',
user.username,
str(error)
......@@ -153,7 +154,7 @@ def download_avatar_image(user, size):
url = avatar_for_email(user.email, size)
request = urllib2.Request(url)
request.timeout = 0.5
request.add_header('User-Agent', weblate.USER_AGENT)
request.add_header('User-Agent', USER_AGENT)
# Fire request
handle = urllib2.urlopen(request)
......
......@@ -31,7 +31,7 @@ from django.contrib.auth.models import User
from django.utils.encoding import force_unicode
from itertools import chain
import unicodedata
import weblate
from weblate.logger import LOGGER
try:
import pyuca # pylint: disable=import-error
......@@ -399,7 +399,7 @@ class CaptchaRegistrationForm(RegistrationForm):
else:
mail = 'NONE'
weblate.logger.info(
LOGGER.info(
'Passed captcha for %s (%s = %s)',
mail,
self.captcha.question,
......
......@@ -42,7 +42,8 @@ from weblate.trans.site import get_site_url, get_site_domain
from weblate.accounts.avatar import get_user_display
from weblate.trans.util import report_error
from weblate.trans.signals import user_pre_delete
import weblate
from weblate import VERSION
from weblate.logger import LOGGER
from weblate.appsettings import ANONYMOUS_USER_NAME, SITE_TITLE
......@@ -52,7 +53,7 @@ def send_mails(mails):
connection = get_connection()
connection.send_messages(mails)
except SMTPException as error:
weblate.logger.error('Failed to send email: %s', error)
LOGGER.error('Failed to send email: %s', error)
report_error(error, sys.exc_info())
......@@ -270,7 +271,7 @@ def get_notification_email(language, email, notification,
try:
if info is None:
info = translation_obj.__unicode__()
weblate.logger.info(
LOGGER.info(
'sending notification %s on %s to %s',
notification,
info,
......@@ -315,7 +316,7 @@ def get_notification_email(language, email, notification,
headers['Auto-Submitted'] = 'auto-generated'
headers['X-AutoGenerated'] = 'yes'
headers['Precedence'] = 'bulk'
headers['X-Mailer'] = 'Weblate {}'.format(weblate.VERSION)
headers['X-Mailer'] = 'Weblate {}'.format(VERSION)
# Reply to header
if user is not None:
......
......@@ -33,7 +33,7 @@ from social.exceptions import (
from weblate.accounts.models import send_notification_email, VerifiedEmail
from weblate import appsettings
import weblate
from weblate import USER_AGENT
def get_github_email(access_token):
......@@ -41,7 +41,7 @@ def get_github_email(access_token):
request = urllib2.Request('https://api.github.com/user/emails')
request.timeout = 1.0
request.add_header('User-Agent', weblate.USER_AGENT)
request.add_header('User-Agent', USER_AGENT)
request.add_header(
'Authorization',
'token {0}'.format(access_token)
......
......@@ -45,7 +45,7 @@ from social.backends.utils import load_backends
from social.apps.django_app.utils import BACKENDS
from social.apps.django_app.views import complete
import weblate
from weblate.logger import LOGGER
from weblate.accounts.avatar import get_avatar_image, get_fallback_avatar_url
from weblate.accounts.models import set_lang, remove_user, Profile
from weblate.trans.models import Change, Project, SubProject
......@@ -95,7 +95,7 @@ def mail_admins_contact(request, subject, message, context, sender):
'''
Sends a message to the admins, as defined by the ADMINS setting.
'''
weblate.logger.info(
LOGGER.info(
'contact form from %s',
sender,
)
......@@ -104,7 +104,7 @@ def mail_admins_contact(request, subject, message, context, sender):
request,
_('Message could not be sent to administrator!')
)
weblate.logger.error(
LOGGER.error(
'ADMINS not configured, can not send message!'
)
return
......
......@@ -30,7 +30,7 @@ from translate.lang.data import languages
from weblate.lang import data
from weblate.trans.mixins import PercentMixin
from weblate.appsettings import SIMPLIFY_LANGUAGES
import weblate
from weblate.logger import LOGGER
def get_plural_type(code, pluralequation):
......@@ -60,7 +60,7 @@ def get_plural_type(code, pluralequation):
return data.PLURAL_ARABIC
# Log error in case of uknown mapping
weblate.logger.error(
LOGGER.error(
'Can not guess type of plural for %s: %s', code, pluralequation
)
......
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2015 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import logging
LOGGER = logging.getLogger('weblate')
......@@ -37,7 +37,8 @@ from weblate.trans.specialchars import get_special_chars
from weblate.trans.validators import validate_check_flags
from weblate.accounts.forms import sort_choices
from urllib import urlencode
import weblate
from weblate.logger import LOGGER
from weblate import get_doc_url
ICON_TEMPLATE = u'''
<i class="fa fa-{0}"></i> {1}
......@@ -208,7 +209,7 @@ class PluralTextarea(forms.Textarea):
lang.pluralequation
)
pluralmsg = PLURALS_TEMPLATE.format(
weblate.get_doc_url('user/translating', 'plurals'),
get_doc_url('user/translating', 'plurals'),
ugettext('Documentation for plurals.'),
pluralinfo
)
......@@ -275,7 +276,7 @@ class ChecksumForm(forms.Form):
checksum=self.cleaned_data['checksum'],
)[0]
except (Unit.DoesNotExist, IndexError):
weblate.logger.error(
LOGGER.error(
'message %s disappeared!',
self.cleaned_data['checksum']
)
......@@ -768,7 +769,7 @@ class CheckFlagsForm(forms.Form):
'Please enter a comma separated list of check flags, '
'see <a href="{url}">documentation</a> for more details.'
).format(
url=weblate.get_doc_url('admin/checks', 'custom-checks')
url=get_doc_url('admin/checks', 'custom-checks')
)
def clean_flags(self):
......
......@@ -28,7 +28,8 @@ import sys
import json
import urllib
import urllib2
import weblate
from weblate import USER_AGENT
from weblate.logger import LOGGER
from weblate.trans.util import report_error
......@@ -86,7 +87,7 @@ class MachineTranslation(object):
# Create request object with custom headers
request = urllib2.Request(url)
request.timeout = 0.5
request.add_header('User-Agent', weblate.USER_AGENT)
request.add_header('User-Agent', USER_AGENT)
# Optional authentication
if not skip_auth:
self.authenticate(request)
......@@ -177,11 +178,11 @@ class MachineTranslation(object):
exc, sys.exc_info(),
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
weblate.logger.error(
LOGGER.error(
'Failed to fetch languages from %s, using defaults',
self.name,
)
weblate.logger.error(
LOGGER.error(
'Last fetched URL: %s, params: %s',
self.request_url,
self.request_params,
......@@ -230,11 +231,11 @@ class MachineTranslation(object):
exc, sys.exc_info(),
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
weblate.logger.error(
LOGGER.error(
'Failed to fetch translations from %s',
self.name,
)
weblate.logger.error(
LOGGER.error(
'Last fetched URL: %s, params: %s',
self.request_url,
self.request_params,
......
......@@ -32,7 +32,7 @@ import os
import re
import shutil
import fnmatch
import weblate
from weblate.logger import LOGGER
class Command(BaseCommand):
......@@ -85,7 +85,7 @@ class Command(BaseCommand):
self.name_template = None
self.base_file_template = None
self.vcs = None
self.logger = weblate.logger
self.logger = LOGGER
self._mask_regexp = None
def format_string(self, template, match):
......
......@@ -22,7 +22,7 @@ import os
from django.core.urlresolvers import reverse
import weblate
from weblate.logger import LOGGER
class PercentMixin(object):
......@@ -134,22 +134,22 @@ class LoggerMixin(object):
return 'default: '
def log_debug(self, msg, *args):
return weblate.logger.debug(
return LOGGER.debug(
self.log_prefix + msg, *args
)
def log_info(self, msg, *args):
return weblate.logger.info(
return LOGGER.info(
self.log_prefix + msg, *args
)
def log_warning(self, msg, *args):
return weblate.logger.warning(
return LOGGER.warning(
self.log_prefix + msg, *args
)
def log_error(self, msg, *args):
return weblate.logger.error(
return LOGGER.error(
self.log_prefix + msg, *args
)
......
......@@ -27,7 +27,7 @@ from importlib import import_module
import os
import urlparse
import hashlib
import weblate
from weblate.logger import LOGGER
from weblate.trans.data import data_dir
try:
......@@ -221,7 +221,7 @@ def report_error(error, exc_info, request=None, extra_data=None):
if HAS_ROLLBAR and hasattr(settings, 'ROLLBAR'):
rollbar.report_exc_info(exc_info, request, extra_data=extra_data)
weblate.logger.error(
LOGGER.error(
'Handled exception %s: %s',
error.__class__.__name__,
str(error)
......
......@@ -29,7 +29,7 @@ from weblate.trans.views.helper import get_project, get_subproject
from weblate.trans.site import get_site_url
import json
import weblate
from weblate.logger import LOGGER
import threading
import re
......@@ -154,7 +154,7 @@ def vcs_service_hook(request, service):
# Get service helper
if service not in HOOK_HANDLERS:
weblate.logger.error('service %s is not supported', service)
LOGGER.error('service %s is not supported', service)
return HttpResponseBadRequest('invalid service')
hook_helper = HOOK_HANDLERS[service]
......@@ -162,7 +162,7 @@ def vcs_service_hook(request, service):
try:
service_data = hook_helper(data)
except KeyError:
weblate.logger.error('failed to parse service %s data', service)
LOGGER.error('failed to parse service %s data', service)
return HttpResponseBadRequest('Invalid data in json payload!')
# Log data
......@@ -171,7 +171,7 @@ def vcs_service_hook(request, service):
repo_url = service_data['repo_url']
branch = service_data['branch']
weblate.logger.info(
LOGGER.info(
'received %s notification on repository %s, branch %s',
service_long_name, repo_url, branch
)
......@@ -185,7 +185,7 @@ def vcs_service_hook(request, service):
for obj in subprojects:
if not obj.project.enable_hooks:
continue
weblate.logger.info(
LOGGER.info(
'%s notification will update %s',
service_long_name,
obj
......@@ -233,7 +233,7 @@ def bitbucket_hook_helper(data):
elif data['repository']['scm'] == 'hg':
repos = [repo % params for repo in BITBUCKET_HG_REPOS]
else:
weblate.logger.error(
LOGGER.error(
'unsupported repository: %s',
repr(data['repositoru'])
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment