Commit 4635b56 Use custom logger on all module so we can configure finely the logging

14 files Authored and Committed by pingou 7 months ago
Use custom logger on all module so we can configure finely the logging

And be consistent in the variable name use for it

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>

    
 1 @@ -25,7 +25,7 @@
 2   import trollius_redis
 3   
 4   
 5 - LOG = logging.getLogger(__name__)
 6 + _log = logging.getLogger(__name__)
 7   
 8   if 'PAGURE_CONFIG' not in os.environ \
 9           and os.path.exists('/etc/pagure/pagure.cfg'):
10 @@ -59,7 +59,7 @@
11       # Inside a while loop, wait for incoming events.
12       while True:
13           reply = yield trollius.From(subscriber.next_published())
14 -         LOG.info(
15 +         _log.info(
16               'Received: %s on channel: %s',
17               repr(reply.value), reply.channel)
18           data = json.loads(reply.value)
19 @@ -67,19 +67,19 @@
20           pr_id = data['pr']['id']
21           pr_uid = data['pr']['uid']
22           branch = data['pr']['branch_from']
23 -         LOG.info('Looking for PR: %s', pr_uid)
24 +         _log.info('Looking for PR: %s', pr_uid)
25           session = pagure.lib.create_session(pagure.APP.config['DB_URL'])
26           request = pagure.lib.get_request_by_uid(session, pr_uid)
27   
28 -         LOG.info('PR retrieved: %s', request)
29 +         _log.info('PR retrieved: %s', request)
30   
31           if not request:
32 -             LOG.warning(
33 +             _log.warning(
34                   'No request could be found from the message %s', data)
35               session.close()
36               continue
37   
38 -         LOG.info(
39 +         _log.info(
40               "Trigger on %s PR #%s from %s: %s",
41               request.project.fullname, pr_id,
42               request.project_from.fullname, branch)
43 @@ -91,7 +91,7 @@
44               repo = '%s/%s' % (
45                   pagure.APP.config['GIT_URL_GIT'].rstrip('/'),
46                   request.project_from.path)
47 -             LOG.info(
48 +             _log.info(
49                   'Triggering the build at: %s, for repo: %s', url, repo)
50               requests.post(
51                   url,
52 @@ -103,10 +103,10 @@
53                   }
54               )
55           else:
56 -             LOG.warning('Un-supported CI type')
57 +             _log.warning('Un-supported CI type')
58   
59           session.close()
60 -         LOG.info('Ready for another')
61 +         _log.info('Ready for another')
62   
63   
64   def main():
65 @@ -124,9 +124,9 @@
66       except trollius.ConnectionResetError:
67           pass
68   
69 -     LOG.info("End Connection")
70 +     _log.info("End Connection")
71       loop.close()
72 -     LOG.info("End")
73 +     _log.info("End")
74   
75   
76   if __name__ == '__main__':
77 @@ -136,7 +136,7 @@
78       logging.basicConfig(level=logging.DEBUG)
79   
80       # setup console logging
81 -     LOG.setLevel(logging.DEBUG)
82 +     _log.setLevel(logging.DEBUG)
83       shellhandler = logging.StreamHandler()
84       shellhandler.setLevel(logging.DEBUG)
85   
86 @@ -146,5 +146,5 @@
87       aslog.setLevel(logging.DEBUG)
88   
89       shellhandler.setFormatter(formatter)
90 -     LOG.addHandler(shellhandler)
91 +     _log.addHandler(shellhandler)
92       main()
 1 @@ -45,7 +45,7 @@
 2   SHANDLER.setLevel(APP.config.get('log_level', 'INFO'))
 3   APP.logger.addHandler(SHANDLER)
 4   
 5 - LOG = APP.logger
 6 + _log = logging.getLogger(__name__)
 7   
 8   TMPL_HTML = '''
 9   <!DOCTYPE html>
10 @@ -185,7 +185,7 @@
11           except pagure.exceptions.FileNotFoundException as err:
12               flask.flash(err.message, 'error')
13           except Exception as err:
14 -             LOG.exception(err)
15 +             _log.exception(err)
16               flask.abort(500, 'Unkown error encountered and reported')
17   
18       mimetype = None
 1 @@ -5,6 +5,7 @@
 2   relates to an issue.
 3   """
 4   
 5 + import logging
 6   import os
 7   import sys
 8   
 9 @@ -22,6 +23,8 @@
10   import pagure.lib.link  # noqa: E402
11   
12   
13 + _log = logging.getLogger(__name__)
14 + 
15   abspath = os.path.abspath(os.environ['GIT_DIR'])
16   
17   
18 @@ -86,7 +89,7 @@
19           print err
20       except SQLAlchemyError as err:  # pragma: no cover
21           pagure.SESSION.rollback()
22 -         pagure.APP.logger.exception(err)
23 +         _log.exception(err)
24   
25   
26   def fixes_relation(commitid, relation, app_url=None):
27 @@ -131,7 +134,7 @@
28           print err
29       except SQLAlchemyError as err:  # pragma: no cover
30           pagure.SESSION.rollback()
31 -         pagure.LOG.exception(err)
32 +         _log.exception(err)
33   
34       try:
35           if relation.isa == 'issue':
36 @@ -154,7 +157,7 @@
37       except SQLAlchemyError as err:  # pragma: no cover
38           pagure.SESSION.rollback()
39           print 'ERROR', err
40 -         pagure.LOG.exception(err)
41 +         _log.exception(err)
42   
43   
44   def run_as_post_receive_hook():
 1 @@ -43,7 +43,7 @@
 2   
 3   BASE = declarative_base(metadata=MetaData(naming_convention=CONVENTION))
 4   
 5 - ERROR_LOG = logging.getLogger('pagure.model')
 6 + _log = logging.getLogger(__name__)
 7   
 8   # hit w/ all the id field we use
 9   # pylint: disable=invalid-name
10 @@ -114,7 +114,7 @@
11               session.commit()
12           except SQLAlchemyError:  # pragma: no cover
13               session.rollback()
14 -             ERROR_LOG.debug('Status %s could not be added', ticket_stat)
15 +             _log.debug('Status %s could not be added', ticket_stat)
16   
17       for status in ['Open', 'Closed', 'Merged']:
18           pr_stat = StatusPullRequest(status=status)
19 @@ -123,7 +123,7 @@
20               session.commit()
21           except SQLAlchemyError:  # pragma: no cover
22               session.rollback()
23 -             ERROR_LOG.debug('Status %s could not be added', pr_stat)
24 +             _log.debug('Status %s could not be added', pr_stat)
25   
26       for grptype in ['user', 'admin']:
27           grp_type = PagureGroupType(group_type=grptype)
28 @@ -132,7 +132,7 @@
29               session.commit()
30           except SQLAlchemyError:  # pragma: no cover
31               session.rollback()
32 -             ERROR_LOG.debug('Type %s could not be added', grptype)
33 +             _log.debug('Type %s could not be added', grptype)
34   
35       for acl in sorted(acls) or {}:
36           item = ACL(
37 @@ -144,7 +144,7 @@
38               session.commit()
39           except SQLAlchemyError:  # pragma: no cover
40               session.rollback()
41 -             ERROR_LOG.debug('ACL %s could not be added', acl)
42 +             _log.debug('ACL %s could not be added', acl)
43   
44       for access in ['ticket', 'commit', 'admin']:
45           access_obj = AccessLevels(access=access)
46 @@ -153,7 +153,7 @@
47               session.commit()
48           except SQLAlchemyError:
49               session.rollback()
50 -             ERROR_LOG.debug('Access level %s could not be added', access)
51 +             _log.debug('Access level %s could not be added', access)
52   
53   
54   class AccessLevels(BASE):
 1 @@ -1,7 +1,7 @@
 2   # -*- coding: utf-8 -*-
 3   
 4   """
 5 -  (c) 2014-2016 - Copyright Red Hat Inc
 6 +  (c) 2014-2017 - Copyright Red Hat Inc
 7   
 8    Authors:
 9      Pierre-Yves Chibon <pingou@pingoured.fr>
10 @@ -17,6 +17,7 @@
11   import datetime
12   import hashlib
13   import json
14 + import logging
15   import urlparse
16   import re
17   import smtplib
18 @@ -30,6 +31,9 @@
19   from email.mime.text import MIMEText
20   
21   
22 + _log = logging.getLogger(__name__)
23 + 
24 + 
25   REPLY_MSG = 'To reply, visit the link below'
26   if pagure.APP.config['EVENTSOURCE_SOURCE']:
27       REPLY_MSG += ' or just reply to this email'
28 @@ -286,7 +290,7 @@
29                   [mailto],
30                   msg.as_string())
31           except smtplib.SMTPException as err:
32 -             pagure.LOG.exception(err)
33 +             _log.exception(err)
34       if smtp:
35           smtp.quit()
36       return msg
 1 @@ -1,13 +1,14 @@
 2   # -*- coding: utf-8 -*-
 3   
 4   """
 5 -  (c) 2015-2016 - Copyright Red Hat Inc
 6 +  (c) 2015-2017 - Copyright Red Hat Inc
 7   
 8    Authors:
 9      Pierre-Yves Chibon <pingou@pingoured.fr>
10   
11   """
12   
13 + import logging
14   import os
15   import subprocess
16   
17 @@ -17,6 +18,9 @@
18   import pagure.exceptions
19   
20   
21 + _log = logging.getLogger(__name__)
22 + 
23 + 
24   def get_pygit2_version():
25       ''' Return pygit2 version as a tuple of integers.
26       This is needed for correct version comparison.
27 @@ -74,7 +78,7 @@
28                       raise pagure.exceptions.GitConflictsException(
29                           'Pulling remote changes leads to a conflict')
30                   else:
31 -                     pagure.LOG.debug(
32 +                     _log.debug(
33                           'Un-expected merge result: %s' % (
34                               pygit2.GIT_MERGE_ANALYSIS_NORMAL))
35                       raise AssertionError('Unknown merge analysis result')
 1 @@ -10,6 +10,7 @@
 2   """
 3   
 4   import datetime
 5 + import logging
 6   from math import ceil
 7   
 8   import flask
 9 @@ -24,6 +25,9 @@
10                       authenticated, admin_session_timedout)
11   
12   
13 + _log = logging.getLogger(__name__)
14 + 
15 + 
16   @APP.route('/browse/projects', endpoint='browse_projects')
17   @APP.route('/browse/projects/', endpoint='browse_projects')
18   @APP.route('/')
19 @@ -631,7 +635,7 @@
20               flask.flash('Email removed')
21           except SQLAlchemyError as err:  # pragma: no cover
22               SESSION.rollback()
23 -             APP.logger.exception(err)
24 +             _log.exception(err)
25               flask.flash('Email could not be removed', 'error')
26   
27       return flask.redirect(flask.url_for('.user_settings'))
28 @@ -666,7 +670,7 @@
29               flask.flash(str(err), 'error')
30           except SQLAlchemyError as err:  # pragma: no cover
31               SESSION.rollback()
32 -             APP.logger.exception(err)
33 +             _log.exception(err)
34               flask.flash('Email could not be added', 'error')
35   
36       return flask.render_template(
37 @@ -711,7 +715,7 @@
38               flask.flash('Default email set to: %s' % email)
39           except SQLAlchemyError as err:  # pragma: no cover
40               SESSION.rollback()
41 -             APP.logger.exception(err)
42 +             _log.exception(err)
43               flask.flash('Default email could not be set', 'error')
44   
45       return flask.redirect(flask.url_for('.user_settings'))
46 @@ -743,7 +747,7 @@
47               flask.flash(str(err), 'error')
48           except SQLAlchemyError as err:  # pragma: no cover
49               SESSION.rollback()
50 -             APP.logger.exception(err)
51 +             _log.exception(err)
52               flask.flash('Confirmation email could not be re-sent', 'error')
53   
54       return flask.redirect(flask.url_for('.user_settings'))
55 @@ -772,7 +776,7 @@
56               flask.flash(
57                   'Could not set the account as active in the db, '
58                   'please report this error to an admin', 'error')
59 -             APP.logger.exception(err)
60 +             _log.exception(err)
61   
62       return flask.redirect(flask.url_for('.user_settings'))
63   
64 @@ -824,7 +828,7 @@
65               return flask.redirect(flask.url_for('.user_settings'))
66           except SQLAlchemyError as err:  # pragma: no cover
67               SESSION.rollback()
68 -             APP.logger.exception(err)
69 +             _log.exception(err)
70               flask.flash('API key could not be added', 'error')
71   
72       # When form is displayed after an empty submission, show an error.
73 @@ -868,7 +872,7 @@
74               flask.flash('Token revoked')
75           except SQLAlchemyError as err:  # pragma: no cover
76               SESSION.rollback()
77 -             APP.logger.exception(err)
78 +             _log.exception(err)
79               flask.flash(
80                   'Token could not be revoked, please contact an admin',
81                   'error')
  1 @@ -16,10 +16,11 @@
  2   # pylint: disable=too-many-lines
  3   
  4   
  5 - import flask
  6 + import logging
  7   import os
  8   from math import ceil
  9   
 10 + import flask
 11   import filelock
 12   import pygit2
 13   from sqlalchemy.exc import SQLAlchemyError
 14 @@ -33,6 +34,9 @@
 15   from pagure import APP, SESSION, login_required, __get_file_in_tree
 16   
 17   
 18 + _log = logging.getLogger(__name__)
 19 + 
 20 + 
 21   def _get_parent_repo_path(repo):
 22       """ Return the path of the parent git repository corresponding to the
 23       provided Repository object from the DB.
 24 @@ -224,7 +228,7 @@
 25                   namespace=namespace))
 26           except SQLAlchemyError as err:  # pragma: no cover
 27               SESSION.rollback()
 28 -             APP.logger.exception(err)
 29 +             _log.exception(err)
 30               flask.flash(
 31                   'Could not update this pull-request in the database',
 32                   'error')
 33 @@ -309,7 +313,7 @@
 34                   namespace=namespace))
 35           except SQLAlchemyError as err:  # pragma: no cover
 36               SESSION.rollback()
 37 -             APP.logger.exception(err)
 38 +             _log.exception(err)
 39               flask.flash(
 40                   'Could not update this pull-request in the database',
 41                   'error')
 42 @@ -375,7 +379,7 @@
 43               flask.flash('Pull request edited!')
 44           except SQLAlchemyError as err:  # pragma: no cover
 45               SESSION.rollback()
 46 -             APP.logger.exception(err)
 47 +             _log.exception(err)
 48               flask.flash(
 49                   'Could not edit this pull-request in the database',
 50                   'error')
 51 @@ -463,14 +467,14 @@
 52                   flask.flash(message)
 53           except SQLAlchemyError as err:  # pragma: no cover
 54               SESSION.rollback()
 55 -             APP.logger.exception(err)
 56 +             _log.exception(err)
 57               if is_js:
 58                   return 'error'
 59               else:
 60                   flask.flash(str(err), 'error')
 61           except filelock.Timeout as err:  # pragma: no cover
 62               SESSION.rollback()
 63 -             APP.logger.exception(err)
 64 +             _log.exception(err)
 65               if is_js:
 66                   return 'error'
 67               else:
 68 @@ -562,7 +566,7 @@
 69                   flask.flash('Comment removed')
 70               except SQLAlchemyError as err:  # pragma: no cover
 71                   SESSION.rollback()
 72 -                 APP.logger.error(err)
 73 +                 _log.error(err)
 74                   flask.flash(
 75                       'Could not remove the comment: %s' % commentid, 'error')
 76   
 77 @@ -632,7 +636,7 @@
 78                   flask.flash(message)
 79           except SQLAlchemyError, err:  # pragma: no cover
 80               SESSION.rollback()
 81 -             APP.logger.error(err)
 82 +             _log.error(err)
 83               if is_js:
 84                   return 'error'
 85               else:
 86 @@ -640,7 +644,7 @@
 87                       'Could not edit the comment: %s' % commentid, 'error')
 88           except filelock.Timeout as err:  # pragma: no cover
 89               SESSION.rollback()
 90 -             APP.logger.exception(err)
 91 +             _log.exception(err)
 92               if is_js:
 93                   return 'error'
 94               else:
 95 @@ -790,13 +794,13 @@
 96               flask.flash('Pull request canceled!')
 97           except SQLAlchemyError as err:  # pragma: no cover
 98               SESSION.rollback()
 99 -             APP.logger.exception(err)
100 +             _log.exception(err)
101               flask.flash(
102                   'Could not update this pull-request in the database',
103                   'error')
104           except filelock.Timeout as err:  # pragma: no cover
105               SESSION.rollback()
106 -             APP.logger.exception(err)
107 +             _log.exception(err)
108               flask.flash(
109                   'We could not save all the info, please try again',
110                   'error')
111 @@ -857,11 +861,11 @@
112               flask.flash(err.message, 'error')
113           except SQLAlchemyError as err:  # pragma: no cover
114               SESSION.rollback()
115 -             APP.logger.exception(err)
116 +             _log.exception(err)
117               flask.flash(str(err), 'error')
118           except filelock.Timeout as err:  # pragma: no cover
119               SESSION.rollback()
120 -             APP.logger.exception(err)
121 +             _log.exception(err)
122               flask.flash(
123                   'We could not save all the info, please try again',
124                   'error')
125 @@ -1011,7 +1015,7 @@
126                   SESSION.commit()
127               except SQLAlchemyError as err:  # pragma: no cover
128                   SESSION.rollback()
129 -                 APP.logger.exception(err)
130 +                 _log.exception(err)
131                   flask.flash(
132                       'Could not register this pull-request in the database',
133                       'error')
134 @@ -1037,7 +1041,7 @@
135               flask.flash(str(err), 'error')
136           except filelock.Timeout as err:  # pragma: no cover
137               SESSION.rollback()
138 -             APP.logger.exception(err)
139 +             _log.exception(err)
140               flask.flash(
141                   'We could not save all the info, please try again',
142                   'error')
143 @@ -1191,7 +1195,7 @@
144                   flask.flash('Request created')
145               except SQLAlchemyError as err:  # pragma: no cover
146                   SESSION.rollback()
147 -                 APP.logger.exception(err)
148 +                 _log.exception(err)
149                   flask.flash(
150                       'Could not register this pull-request in '
151                       'the database', 'error')
 1 @@ -8,8 +8,9 @@
 2   
 3   """
 4   
 5 - import flask
 6 + import logging
 7   
 8 + import flask
 9   from sqlalchemy.exc import SQLAlchemyError
10   
11   import pagure
12 @@ -18,6 +19,9 @@
13   import pagure.lib.git
14   
15   
16 + _log = logging.getLogger(__name__)
17 + 
18 + 
19   @pagure.APP.route('/groups/')
20   @pagure.APP.route('/groups')
21   def group_lists():
22 @@ -93,10 +97,9 @@
23                   'Could not add user `%s` to group `%s`.' % (
24                       username, group.group_name),
25                   'error')
26 -             pagure.APP.logger.debug(
27 +             _log.exception(
28                   'Could not add user `%s` to group `%s`.' % (
29                       username, group.group_name))
30 -             pagure.APP.logger.exception(err)
31   
32       member = False
33       if pagure.authenticated():
34 @@ -156,9 +159,8 @@
35               flask.flash(
36                   'Could not edit group `%s`.' % (group.group_name),
37                   'error')
38 -             pagure.APP.logger.debug(
39 +             _log.exception(
40                   'Could not edit group `%s`.' % (group.group_name))
41 -             pagure.APP.logger.exception(err)
42       elif flask.request.method == 'GET':
43           form.display_name.data = group.display_name
44           form.description.data = group.description
45 @@ -207,10 +209,9 @@
46                   'Could not remove user `%s` from the group `%s`.' % (
47                       user.user, group),
48                   'error')
49 -             pagure.APP.logger.debug(
50 +             _log.exception(
51                   'Could not remove user `%s` from the group `%s`.' % (
52                       user.user, group))
53 -             pagure.APP.logger.exception(err)
54   
55       return flask.redirect(flask.url_for('.view_group', group=group))
56   
57 @@ -314,8 +315,7 @@
58           except SQLAlchemyError as err:  # pragma: no cover
59               pagure.SESSION.rollback()
60               flask.flash('Could not create group.')
61 -             pagure.APP.logger.debug('Could not create group.')
62 -             pagure.APP.logger.exception(err)
63 +             _log.exception('Could not create group.')
64   
65       return flask.render_template(
66           'add_group.html',
  1 @@ -15,12 +15,13 @@
  2   
  3   
  4   import datetime
  5 - import flask
  6 + import logging
  7   import os
  8   import re
  9   from collections import defaultdict
 10   from math import ceil
 11   
 12 + import flask
 13   import filelock
 14   import pygit2
 15   import werkzeug.datastructures
 16 @@ -39,6 +40,8 @@
 17                       login_required, authenticated, urlpattern)
 18   
 19   
 20 + _log = logging.getLogger(__name__)
 21 + 
 22   # URLs
 23   
 24   
 25 @@ -136,7 +139,7 @@
 26               except SQLAlchemyError as err:  # pragma: no cover
 27                   is_js = False
 28                   SESSION.rollback()
 29 -                 APP.logger.error(err)
 30 +                 _log.error(err)
 31                   if not is_js:
 32                       flask.flash(
 33                           'Could not remove the comment: %s' % commentid,
 34 @@ -340,12 +343,12 @@
 35           except SQLAlchemyError as err:  # pragma: no cover
 36               is_js = False
 37               SESSION.rollback()
 38 -             APP.logger.exception(err)
 39 +             _log.exception(err)
 40               flask.flash(str(err), 'error')
 41           except filelock.Timeout as err:  # pragma: no cover
 42               is_js = False
 43               SESSION.rollback()
 44 -             APP.logger.exception(err)
 45 +             _log.exception(err)
 46               flask.flash(
 47                   'We could not save all the info, please try again',
 48                   'error')
 49 @@ -428,7 +431,7 @@
 50                   flask.flash(msg)
 51           except SQLAlchemyError as err:  # pragma: no cover
 52               SESSION.rollback()
 53 -             APP.logger.error(err)
 54 +             _log.error(err)
 55               flask.flash('Could not edit tag: %s' % tag, 'error')
 56   
 57           return flask.redirect(flask.url_for(
 58 @@ -575,7 +578,7 @@
 59                   flask.flash(msg)
 60           except SQLAlchemyError as err:  # pragma: no cover
 61               SESSION.rollback()
 62 -             APP.logger.error(err)
 63 +             _log.error(err)
 64               flask.flash(
 65                   'Could not remove tag: %s' % ','.join(tags), 'error')
 66   
 67 @@ -943,7 +946,7 @@
 68               flask.flash(str(err), 'error')
 69           except filelock.Timeout as err:  # pragma: no cover
 70               SESSION.rollback()
 71 -             APP.logger.exception(err)
 72 +             _log.exception(err)
 73               flask.flash(
 74                   'We could not save all the info, please try again',
 75                   'error')
 76 @@ -1092,7 +1095,7 @@
 77                   namespace=namespace))
 78           except SQLAlchemyError as err:  # pragma: no cover
 79               SESSION.rollback()
 80 -             APP.logger.exception(err)
 81 +             _log.exception(err)
 82               flask.flash('Could not delete the issue', 'error')
 83   
 84       return flask.redirect(flask.url_for(
 85 @@ -1212,7 +1215,7 @@
 86               flask.flash(str(err), 'error')
 87           except filelock.Timeout as err:  # pragma: no cover
 88               SESSION.rollback()
 89 -             APP.logger.exception(err)
 90 +             _log.exception(err)
 91               flask.flash(
 92                   'We could not save all the info, please try again',
 93                   'error')
 94 @@ -1278,7 +1281,7 @@
 95               )
 96           except filelock.Timeout as err:  # pragma: no cover
 97               SESSION.rollback()
 98 -             APP.logger.exception(err)
 99 +             _log.exception(err)
100               flask.flash(
101                   'We could not save all the info, please try again',
102                   'error')
103 @@ -1373,7 +1376,7 @@
104                   ktc.to_bytes(data))
105           except pagure.exceptions.PagureException:
106               # We cannot decode the file, so bail but warn the admins
107 -             APP.logger.exception('File could not be decoded')
108 +             _log.exception('File could not be decoded')
109   
110       if encoding:
111           mimetype += '; charset={encoding}'.format(encoding=encoding)
112 @@ -1437,14 +1440,14 @@
113                   flask.flash(message)
114           except SQLAlchemyError, err:  # pragma: no cover
115               SESSION.rollback()
116 -             APP.logger.error(err)
117 +             _log.error(err)
118               if is_js:
119                   return 'error'
120               flask.flash(
121                   'Could not edit the comment: %s' % commentid, 'error')
122           except filelock.Timeout as err:  # pragma: no cover
123               SESSION.rollback()
124 -             APP.logger.exception(err)
125 +             _log.exception(err)
126               flask.flash(
127                   'We could not save all the info, please try again',
128                   'error')
  1 @@ -1,7 +1,7 @@
  2   # -*- coding: utf-8 -*-
  3   
  4   """
  5 -  (c) 2014-2016 - Copyright Red Hat Inc
  6 +  (c) 2014-2017 - Copyright Red Hat Inc
  7   
  8    Authors:
  9      Pierre-Yves Chibon <pingou@pingoured.fr>
 10 @@ -10,6 +10,7 @@
 11   """
 12   
 13   import datetime
 14 + import logging
 15   import urlparse
 16   
 17   import flask
 18 @@ -24,6 +25,9 @@
 19   from pagure.lib.login import generate_hashed_value, check_password
 20   
 21   
 22 + _log = logging.getLogger(__name__)
 23 + 
 24 + 
 25   @APP.route('/user/new/', methods=['GET', 'POST'])
 26   @APP.route('/user/new', methods=['GET', 'POST'])
 27   def new_user():
 28 @@ -62,11 +66,10 @@
 29               flask.flash(
 30                   'User created, please check your email to activate the '
 31                   'account')
 32 -         except SQLAlchemyError as err:  # pragma: no cover
 33 +         except SQLAlchemyError:  # pragma: no cover
 34               SESSION.rollback()
 35               flask.flash('Could not create user.')
 36 -             APP.logger.debug('Could not create user.')
 37 -             APP.logger.exception(err)
 38 +             _log.exception('Could not create user.')
 39   
 40           return flask.redirect(flask.url_for('auth_login'))
 41   
 42 @@ -97,7 +100,7 @@
 43                   form.password.data, user_obj.password,
 44                   seed=APP.config.get('PASSWORD_SEED', None))
 45           except pagure.exceptions.PagureException as err:
 46 -             APP.logger.exception(err)
 47 +             _log.exception(err)
 48               flask.flash('Username or password of invalid format.', 'error')
 49               return flask.redirect(flask.url_for('auth_login'))
 50   
 51 @@ -137,7 +140,7 @@
 52                   flask.flash(
 53                       'Could not set the session in the db, '
 54                       'please report this error to an admin', 'error')
 55 -                 APP.logger.exception(err)
 56 +                 _log.exception(err)
 57   
 58           return flask.redirect(next_url)
 59       else:
 60 @@ -165,7 +168,7 @@
 61               flask.flash(
 62                   'Could not set the account as active in the db, '
 63                   'please report this error to an admin', 'error')
 64 -             APP.logger.exception(err)
 65 +             _log.exception(err)
 66   
 67       return flask.redirect(flask.url_for('index'))
 68   
 69 @@ -204,13 +207,12 @@
 70               send_lostpassword_email(user_obj)
 71               flask.flash(
 72                   'Check your email to finish changing your password')
 73 -         except SQLAlchemyError as err:  # pragma: no cover
 74 +         except SQLAlchemyError:  # pragma: no cover
 75               SESSION.rollback()
 76               flask.flash(
 77                   'Could not set the token allowing changing a password.',
 78                   'error')
 79 -             APP.logger.debug('Password lost change - Error setting token.')
 80 -             APP.logger.exception(err)
 81 +             _log.exception('Password lost change - Error setting token.')
 82   
 83           return flask.redirect(flask.url_for('auth_login'))
 84   
 85 @@ -248,12 +250,11 @@
 86               SESSION.commit()
 87               flask.flash(
 88                   'Password changed')
 89 -         except SQLAlchemyError as err:  # pragma: no cover
 90 +         except SQLAlchemyError:  # pragma: no cover
 91               SESSION.rollback()
 92               flask.flash('Could not set the new password.', 'error')
 93 -             APP.logger.debug(
 94 +             _log.exception(
 95                   'Password lost change - Error setting password.')
 96 -             APP.logger.exception(err)
 97   
 98           return flask.redirect(flask.url_for('auth_login'))
 99   
100 @@ -288,7 +289,7 @@
101                   form.old_password.data, user_obj.password,
102                   seed=APP.config.get('PASSWORD_SEED', None))
103           except pagure.exceptions.PagureException as err:
104 -             APP.logger.exception(err)
105 +             _log.exception(err)
106               flask.flash(
107                   'Could not update your password, either user or password '
108                   'could not be checked', 'error')
109 @@ -308,12 +309,11 @@
110               SESSION.commit()
111               flask.flash(
112                   'Password changed')
113 -         except SQLAlchemyError as err:  # pragma: no cover
114 +         except SQLAlchemyError:  # pragma: no cover
115               SESSION.rollback()
116               flask.flash('Could not set the new password.', 'error')
117 -             APP.logger.debug(
118 +             _log.exception(
119                   'Password change  - Error setting new password.')
120 -             APP.logger.exception(err)
121   
122           return flask.redirect(flask.url_for('auth_login'))
123   
124 @@ -435,7 +435,7 @@
125                       flask.flash(
126                           'Could not prolong the session in the db, '
127                           'please report this error to an admin', 'error')
128 -                     APP.logger.exception(err)
129 +                     _log.exception(err)
130   
131       flask.g.fas_session_id = session_id
132       flask.g.fas_user = user
 1 @@ -1,7 +1,7 @@
 2   # -*- coding: utf-8 -*-
 3   
 4   """
 5 -  (c) 2014-2016 - Copyright Red Hat Inc
 6 +  (c) 2014-2017 - Copyright Red Hat Inc
 7   
 8    Authors:
 9      Pierre-Yves Chibon <pingou@pingoured.fr>
10 @@ -11,8 +11,9 @@
11   
12   # pylint: disable=too-many-branches
13   
14 - import flask
15 + import logging
16   
17 + import flask
18   from sqlalchemy.exc import SQLAlchemyError
19   
20   import pagure.exceptions
21 @@ -23,6 +24,9 @@
22   from pagure.exceptions import FileNotFoundException
23   
24   
25 + _log = logging.getLogger(__name__)
26 + 
27 + 
28   @APP.route('/<repo>/settings/<plugin>/', methods=('GET', 'POST'))
29   @APP.route('/<repo>/settings/<plugin>', methods=('GET', 'POST'))
30   @APP.route('/<namespace>/<repo>/settings/<plugin>/', methods=('GET', 'POST'))
31 @@ -114,8 +118,7 @@
32               SESSION.flush()
33           except SQLAlchemyError as err:  # pragma: no cover
34               SESSION.rollback()
35 -             APP.logger.debug('Could not add plugin %s', plugin.name)
36 -             APP.logger.exception(err)
37 +             _log.exception('Could not add plugin %s', plugin.name)
38               flask.flash(
39                   'Could not add plugin %s, please contact an admin'
40                   % plugin.name)
41 @@ -139,14 +142,14 @@
42                   plugin.install(repo, dbobj)
43                   flask.flash('Hook %s activated' % plugin.name)
44               except FileNotFoundException as err:
45 -                 pagure.APP.logger.exception(err)
46 +                 _log.exception(err)
47                   flask.abort(404, 'No git repo found')
48           else:
49               try:
50                   plugin.remove(repo)
51                   flask.flash('Hook %s deactivated' % plugin.name)
52               except FileNotFoundException as err:
53 -                 pagure.APP.logger.exception(err)
54 +                 _log.exception(err)
55                   flask.abort(404, 'No git repo found')
56   
57           SESSION.commit()
  1 @@ -19,8 +19,10 @@
  2   
  3   import datetime
  4   import json
  5 + import logging
  6   import shutil
  7   import os
  8 + from cStringIO import StringIO
  9   from math import ceil
 10   
 11   import flask
 12 @@ -28,7 +30,6 @@
 13   import kitchen.text.converters as ktc
 14   import werkzeug
 15   
 16 - from cStringIO import StringIO
 17   from PIL import Image
 18   from pygments import highlight
 19   from pygments.formatters import HtmlFormatter
 20 @@ -54,6 +55,9 @@
 21   from pagure.lib import encoding_utils
 22   
 23   
 24 + _log = logging.getLogger(__name__)
 25 + 
 26 + 
 27   @APP.route('/<repo>.git')
 28   @APP.route('/<namespace>/<repo>.git')
 29   @APP.route('/fork/<username>/<repo>.git')
 30 @@ -492,7 +496,7 @@
 31                   Image.open(StringIO(content.data))
 32                   output_type = 'image'
 33               except IOError as err:
 34 -                 APP.logger.debug(
 35 +                 _log.debug(
 36                       'Failed to load image %s, error: %s', filename, err
 37                   )
 38                   output_type = 'binary'
 39 @@ -658,7 +662,7 @@
 40               encoding = encoding_utils.guess_encoding(ktc.to_bytes(data))
 41           except pagure.exceptions.PagureException:
 42               # We cannot decode the file, so bail but warn the admins
 43 -             APP.logger.exception('File could not be decoded')
 44 +             _log.exception('File could not be decoded')
 45   
 46       if encoding:
 47           mimetype += '; charset={encoding}'.format(encoding=encoding)
 48 @@ -699,7 +703,7 @@
 49           content = encoding_utils.decode(content.data)
 50       except pagure.exceptions.PagureException:
 51           # We cannot decode the file, so bail but warn the admins
 52 -         APP.logger.exception('File could not be decoded')
 53 +         _log.exception('File could not be decoded')
 54           flask.abort(500, 'File could not be decoded')
 55   
 56       lexer = TextLexer()
 57 @@ -959,7 +963,7 @@
 58               except pagure.exceptions.PagureException as err:
 59                   flask.flash(str(err), 'error')
 60               except Exception as err:  # pragma: no cover
 61 -                 APP.logger.exception(err)
 62 +                 _log.exception(err)
 63                   flask.flash('Upload failed', 'error')
 64           return flask.redirect(flask.url_for(
 65               'view_tags', repo=repo.name, username=username,
 66 @@ -1378,7 +1382,7 @@
 67               repo_obj.set_head(reference.name)
 68               flask.flash('Default branch updated to %s' % branchname)
 69           except Exception as err:  # pragma: no cover
 70 -             APP.logger.exception(err)
 71 +             _log.exception(err)
 72   
 73       return flask.redirect(flask.url_for(
 74           'view_settings', username=username, repo=repo.name,
 75 @@ -1416,7 +1420,7 @@
 76           SESSION.commit()
 77       except SQLAlchemyError as err:  # pragma: no cover
 78           SESSION.rollback()
 79 -         APP.logger.exception(err)
 80 +         _log.exception(err)
 81           flask.flash('Could not delete the project', 'error')
 82   
 83       repopath = os.path.join(APP.config['GIT_FOLDER'], repo.path)
 84 @@ -1430,7 +1434,7 @@
 85           shutil.rmtree(ticketpath)
 86           shutil.rmtree(requestpath)
 87       except (OSError, IOError) as err:
 88 -         APP.logger.exception(err)
 89 +         _log.exception(err)
 90           flask.flash(
 91               'Could not delete all the repos from the system', 'error')
 92   
 93 @@ -1475,7 +1479,7 @@
 94           flask.flash('New hook token generated')
 95       except SQLAlchemyError as err:  # pragma: no cover
 96           SESSION.rollback()
 97 -         APP.logger.exception(err)
 98 +         _log.exception(err)
 99           flask.flash('Could not generate a new token for this project', 'error')
100   
101       return flask.redirect(flask.url_for(
102 @@ -1535,7 +1539,7 @@
103               flask.flash('Deploy key removed')
104           except SQLAlchemyError as err:  # pragma: no cover
105               SESSION.rollback()
106 -             APP.logger.exception(err)
107 +             _log.exception(err)
108               flask.flash('Deploy key could not be removed', 'error')
109   
110       return flask.redirect(flask.url_for(
111 @@ -1593,7 +1597,7 @@
112               flask.flash('User removed')
113           except SQLAlchemyError as err:  # pragma: no cover
114               SESSION.rollback()
115 -             APP.logger.exception(err)
116 +             _log.exception(err)
117               flask.flash('User could not be removed', 'error')
118   
119       return flask.redirect(flask.url_for(
120 @@ -1656,7 +1660,7 @@
121               flask.flash(msg, 'error')
122           except SQLAlchemyError as err:  # pragma: no cover
123               SESSION.rollback()
124 -             APP.logger.exception(err)
125 +             _log.exception(err)
126               flask.flash('Deploy key could not be added', 'error')
127   
128       return flask.render_template(
129 @@ -1734,7 +1738,7 @@
130               flask.flash(msg, 'error')
131           except SQLAlchemyError as err:  # pragma: no cover
132               SESSION.rollback()
133 -             APP.logger.exception(err)
134 +             _log.exception(err)
135               flask.flash('User could not be added', 'error')
136   
137       access_levels = pagure.lib.get_access_levels(SESSION)
138 @@ -1801,7 +1805,7 @@
139               flask.flash('Group removed')
140           except SQLAlchemyError as err:  # pragma: no cover
141               SESSION.rollback()
142 -             APP.logger.exception(err)
143 +             _log.exception(err)
144               flask.flash('Group could not be removed', 'error')
145   
146       return flask.redirect(flask.url_for(
147 @@ -1878,7 +1882,7 @@
148               flask.flash(msg, 'error')
149           except SQLAlchemyError as err:  # pragma: no cover
150               SESSION.rollback()
151 -             APP.logger.exception(err)
152 +             _log.exception(err)
153               flask.flash('Group could not be added', 'error')
154   
155       access_levels = pagure.lib.get_access_levels(SESSION)
156 @@ -2006,7 +2010,7 @@
157                   namespace=namespace))
158           except SQLAlchemyError as err:  # pragma: no cover
159               SESSION.rollback()
160 -             APP.logger.exception(err)
161 +             _log.exception(err)
162               flask.flash('User could not be added', 'error')
163   
164       # When form is displayed after an empty submission, show an error.
165 @@ -2067,7 +2071,7 @@
166               flask.flash('Token revoked')
167           except SQLAlchemyError as err:  # pragma: no cover
168               SESSION.rollback()
169 -             APP.logger.exception(err)
170 +             _log.exception(err)
171               flask.flash(
172                   'Token could not be revoked, please contact an admin',
173                   'error')
174 @@ -2138,7 +2142,7 @@
175                       namespace=namespace, branchname=form.branch.data)
176               )
177           except pagure.exceptions.PagureException as err:  # pragma: no cover
178 -             APP.logger.exception(err)
179 +             _log.exception(err)
180               flask.flash('Commit could not be done', 'error')
181               data = form.content.data
182       elif flask.request.method == 'GET':
183 @@ -2195,7 +2199,7 @@
184           branch.delete()
185           flask.flash('Branch `%s` deleted' % branchname)
186       except pygit2.GitError as err:
187 -         APP.logger.exception(err)
188 +         _log.exception(err)
189           flask.flash('Could not delete `%s`' % branchname, 'error')
190   
191       return flask.redirect(flask.url_for(
1 @@ -38,7 +38,6 @@
2           """ Set up the environnment, ran before every tests. """
3           super(PagureFlaskDocstests, self).setUp()
4   
5 -         pagure.docs_server.LOG.handlers = []
6           pagure.docs_server.APP.config['TESTING'] = True
7           pagure.docs_server.SESSION = self.session
8