Merge lp:~diegosarmentero/ubuntu-sso-client/too-verbose into lp:ubuntu-sso-client

Proposed by Diego Sarmentero on 2012-03-07
Status: Merged
Approved by: Diego Sarmentero on 2012-03-12
Approved revision: 905
Merged at revision: 907
Proposed branch: lp:~diegosarmentero/ubuntu-sso-client/too-verbose
Merge into: lp:ubuntu-sso-client
Diff against target: 436 lines (+48/-29)
10 files modified
ubuntu_sso/qt/current_user_sign_in_page.py (+4/-6)
ubuntu_sso/qt/email_verification_page.py (+7/-4)
ubuntu_sso/qt/forgotten_password_page.py (+4/-0)
ubuntu_sso/qt/network_detection_page.py (+5/-1)
ubuntu_sso/qt/reset_password_page.py (+3/-0)
ubuntu_sso/qt/setup_account_page.py (+8/-12)
ubuntu_sso/qt/sso_wizard_page.py (+3/-2)
ubuntu_sso/qt/tests/login_u_p.py (+0/-2)
ubuntu_sso/qt/tests/show_gui.py (+0/-2)
ubuntu_sso/qt/ubuntu_sso_wizard.py (+14/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntu-sso-client/too-verbose
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve on 2012-03-12
Natalia Bidart 2012-03-07 Approve on 2012-03-12
Review via email: mp+96364@code.launchpad.net

Commit Message

- Improve logging operations (LP: #934500).

To post a comment you must log in.
Natalia Bidart (nataliabidart) wrote :

Branch looks good, but I would request a minor tweaks:

* every time you "use" a line from the log, try to have as much info as you can get from your context, so later debugging is easier. For example, here:

        logger.debug('About to emit userLoggedIn signal.')
        self.userLoggedIn.emit(email)

we could be also logging the user email, so we can later distinguish userLoggedIn from different email addresses.

Also, please note that default logging on default installs is INFO, so leave the debug entries for truly debug messages, and migrate to INFO those that are providing important info about the progress of the UI.

Thanks!

review: Needs Fixing
904. By Diego Sarmentero on 2012-03-09

Some improves in the logger

Natalia Bidart (nataliabidart) wrote :

* Please note that there is a decorator "log_call" in ubuntu_sso/logger.py that is being used in some places. You are welcomed to re-use this decorator, if you want. But I will request not do use both, like in this case:

    124 @log_call(logger.error)
    125 def on_password_reset_error(self, app_name, error):
    126 """Action taken when there was an error requesting the reset."""
    127 logger.info('Got error on password reset for %s, error: %s',
    128 app_name, error)

(the log_call was there before your branch).* Can you please make all the log lines for initializePage be debug?

* All the log lines inside error callbacks should be logger.error, an example:

    def on_user_registration_error(self, app_name, error):
        """Let the user know we could not register."""
        logger.info('SetUpAccountPage.on_user_registration_error')
        # errors are returned as a dict with the data we want to show.

* Can you please remove this line? logger.debug('SetUpAccountPage.on_captcha_generation_error')

* Could you please add app_name, email and error to the log lines in setup_account_page.py, when available? (using the log_call decorator will make this very easy, since is done automatically)

* In sso_wizard_page.py, can you please change this:

    162 logger.info('SSOWizardPage - executing setup_page')
to

    162 logger.info('%r - setup_page, backend is %r.', self, self.backend)

so we can detect which child of SSOWizardPage is logging that line.

* In the same file, can you add a logger.error message (or log_call(logger.error) decorator) in the show_error callback? Something like:

    134 logger.error('%r - show_error for app_name %r with message %r.',
    135 self, app_name, message)

* Could you please add some debug messages in UbuntuSSOWizard for all the _move_* callbacks?

Branch is looking great, we really need this for further debugging, specially when we go live with Precise.
Thanks!

review: Needs Fixing
905. By Diego Sarmentero on 2012-03-09

more improves in the logs.

Diego Sarmentero (diegosarmentero) wrote :

> * Please note that there is a decorator "log_call" in ubuntu_sso/logger.py
> that is being used in some places. You are welcomed to re-use this decorator,
> if you want. But I will request not do use both, like in this case:
>
> 124 @log_call(logger.error)
> 125 def on_password_reset_error(self, app_name, error):
> 126 """Action taken when there was an error requesting the
> reset."""
> 127 logger.info('Got error on password reset for %s, error: %s',
> 128 app_name, error)
>
> (the log_call was there before your branch).* Can you please make all the log
> lines for initializePage be debug?
>
> * All the log lines inside error callbacks should be logger.error, an example:
>
> def on_user_registration_error(self, app_name, error):
> """Let the user know we could not register."""
> logger.info('SetUpAccountPage.on_user_registration_error')
> # errors are returned as a dict with the data we want to show.
>
> * Can you please remove this line?
> logger.debug('SetUpAccountPage.on_captcha_generation_error')
>
> * Could you please add app_name, email and error to the log lines in
> setup_account_page.py, when available? (using the log_call decorator will make
> this very easy, since is done automatically)
>
> * In sso_wizard_page.py, can you please change this:
>
> 162 logger.info('SSOWizardPage - executing setup_page')
> to
>
> 162 logger.info('%r - setup_page, backend is %r.', self,
> self.backend)
>
> so we can detect which child of SSOWizardPage is logging that line.
>
> * In the same file, can you add a logger.error message (or
> log_call(logger.error) decorator) in the show_error callback? Something like:
>
> 134 logger.error('%r - show_error for app_name %r with message
> %r.',
> 135 self, app_name, message)
>
> * Could you please add some debug messages in UbuntuSSOWizard for all the
> _move_* callbacks?
>
> Branch is looking great, we really need this for further debugging, specially
> when we go live with Precise.
> Thanks!

Done!

Natalia Bidart (nataliabidart) wrote :

Looks good! Thanls for working on this

review: Approve
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/qt/current_user_sign_in_page.py'
2--- ubuntu_sso/qt/current_user_sign_in_page.py 2012-03-05 21:08:40 +0000
3+++ ubuntu_sso/qt/current_user_sign_in_page.py 2012-03-09 17:35:23 +0000
4@@ -81,6 +81,7 @@
5
6 def initializePage(self):
7 """Setup UI details."""
8+ logger.debug('initializePage - About to show CurrentUserSignInPage')
9 self.setButtonText(QtGui.QWizard.CancelButton, CANCEL_BUTTON)
10 # Layout without custom button 1,
11 # without finish button
12@@ -99,10 +100,8 @@
13
14 def _set_translated_strings(self):
15 """Set the translated strings."""
16- logger.debug('CurrentUserSignInPage._set_translated_strings')
17 self.setTitle(LOGIN_TITLE.format(app_name=self.app_name))
18 self.setSubTitle(LOGIN_SUBTITLE % {'app_name': self.app_name})
19-
20 self.ui.email_label.setText(EMAIL_LABEL)
21 self.ui.password_label.setText(LOGIN_PASSWORD_LABEL)
22 forgotten_text = LINK_STYLE.format(link_url='#',
23@@ -112,7 +111,6 @@
24
25 def _connect_ui(self):
26 """Connect the buttons to perform actions."""
27- logger.debug('CurrentUserSignInPage._connect_buttons')
28 self.ui.forgot_password_label.linkActivated.connect(
29 self.on_forgotten_password)
30 self.ui.email_edit.textChanged.connect(self._validate)
31@@ -130,9 +128,9 @@
32
33 def login(self):
34 """Perform the login using the self.backend."""
35- logger.debug('CurrentUserSignInPage.login')
36 # grab the data from the view and call the backend
37 email = unicode(self.ui.email_edit.text())
38+ logger.info('CurrentUserSignInPage.login for: %s', email)
39 password = unicode(self.ui.password_edit.text())
40 args = (self.app_name, email, password)
41 if self.ping_url:
42@@ -158,11 +156,11 @@
43 logger.info('Logged in for %s', app_name)
44 self.hide_overlay()
45 email = unicode(self.ui.email_edit.text())
46+ logger.debug('About to emit userLoggedIn signal with: (%s).', email)
47 self.userLoggedIn.emit(email)
48- logger.debug('Wizard.loginSuccess emitted.')
49
50 def on_forgotten_password(self, link=None):
51 """Show the user the forgotten password page."""
52- logger.info('Forgotten password')
53 self.hide_overlay()
54+ logger.debug('About to emit passwordForgotten signal')
55 self.passwordForgotten.emit()
56
57=== modified file 'ubuntu_sso/qt/email_verification_page.py'
58--- ubuntu_sso/qt/email_verification_page.py 2012-03-05 20:30:57 +0000
59+++ ubuntu_sso/qt/email_verification_page.py 2012-03-09 17:35:23 +0000
60@@ -71,7 +71,6 @@
61
62 def _connect_ui(self):
63 """Set the connection of signals."""
64- logger.debug('EmailVerificationController._connect_ui')
65 self.ui.verification_code_edit.textChanged.connect(
66 self.validate_form)
67 self.next_button.clicked.connect(self.validate_email)
68@@ -84,7 +83,6 @@
69
70 def _set_translated_strings(self):
71 """Set the different titles."""
72- logger.debug('EmailVerificationController._set_titles')
73 self.header.set_title(VERIFY_EMAIL_TITLE)
74 self.header.set_subtitle(VERIFY_EMAIL_CONTENT % {
75 "app_name": self.app_name,
76@@ -103,7 +101,8 @@
77
78 def validate_email(self):
79 """Call the next action."""
80- logger.debug('EmailVerificationController.validate_email')
81+ logger.debug('EmailVerificationController.validate_email for: %s',
82+ self.email)
83 code = unicode(self.ui.verification_code_edit.text())
84 args = (self.app_name, self.email, self.password, code)
85 self.hide_error()
86@@ -123,12 +122,15 @@
87
88 def on_email_validated(self, app_name, email):
89 """Signal thrown after the email is validated."""
90- logger.info('EmailVerificationController.on_email_validated')
91+ logger.info('EmailVerificationController.on_email_validated for %s, '
92+ 'email: %s', app_name, email)
93 self.hide_overlay()
94 self.registrationSuccess.emit(self.email)
95
96 def on_email_validation_error(self, app_name, error):
97 """Signal thrown when there's a problem validating the email."""
98+ logger.error('Got error on email validation %s, error: %s',
99+ app_name, error)
100 self.hide_overlay()
101 msg = error.pop(ERROR_EMAIL_TOKEN, '')
102 msg += build_general_error_message(error)
103@@ -138,6 +140,7 @@
104
105 def initializePage(self):
106 """Called to prepare the page just before it is shown."""
107+ logger.debug('initializePage - About to show EmailVerificationPage')
108 self.next_button.setDefault(True)
109 self.next_button.setEnabled(False)
110 self.wizard().setButtonLayout([QtGui.QWizard.Stretch])
111
112=== modified file 'ubuntu_sso/qt/forgotten_password_page.py'
113--- ubuntu_sso/qt/forgotten_password_page.py 2012-03-05 20:31:22 +0000
114+++ ubuntu_sso/qt/forgotten_password_page.py 2012-03-09 17:35:23 +0000
115@@ -63,6 +63,7 @@
116
117 def initializePage(self):
118 """Set the initial state of ForgottenPassword page."""
119+ logger.debug('initializePage - About to show ForgottenPasswordPage')
120 self.ui.send_button.setDefault(True)
121 enabled = not self.ui.email_line_edit.text().isEmpty()
122 self.ui.send_button.setEnabled(enabled)
123@@ -98,6 +99,7 @@
124 """Send the request password operation."""
125 self.hide_error()
126 args = (self.app_name, self.email_address)
127+ logger.debug('Sending request new password for %s, email: %s', *args)
128 f = self.backend.request_password_reset_token
129
130 error_handler = partial(self._handle_error, f,
131@@ -113,6 +115,8 @@
132
133 def on_password_reset_token_sent(self, app_name, email):
134 """Action taken when we managed to get the password reset done."""
135+ logger.info('ForgottenPasswordPage.on_password_reset_token_sent for '
136+ '%s, email: %s', app_name, email)
137 # ignore the result and move to the reset page
138 self.hide_overlay()
139 self.passwordResetTokenSent.emit(email)
140
141=== modified file 'ubuntu_sso/qt/network_detection_page.py'
142--- ubuntu_sso/qt/network_detection_page.py 2012-02-29 14:00:12 +0000
143+++ ubuntu_sso/qt/network_detection_page.py 2012-03-09 17:35:23 +0000
144@@ -20,7 +20,7 @@
145 from PyQt4 import QtGui
146
147 from ubuntu_sso import networkstate
148-
149+from ubuntu_sso.logger import setup_logging
150 from ubuntu_sso.qt.sso_wizard_page import SSOWizardPage
151 from ubuntu_sso.qt.ui import network_detection_ui
152 from ubuntu_sso.utils.ui import (
153@@ -31,6 +31,9 @@
154 )
155
156
157+logger = setup_logging('ubuntu_sso.network_detection_page')
158+
159+
160 class NetworkDetectionPage(SSOWizardPage):
161
162 """Widget to show if we don't detect a network connection."""
163@@ -48,6 +51,7 @@
164
165 def initializePage(self):
166 """Set UI details."""
167+ logger.debug('initializePage - About to show NetworkDetectionPage')
168 self.wizard()._next_id = None
169
170 self.setButtonText(QtGui.QWizard.CustomButton1, TRY_AGAIN_BUTTON)
171
172=== modified file 'ubuntu_sso/qt/reset_password_page.py'
173--- ubuntu_sso/qt/reset_password_page.py 2012-03-05 20:30:57 +0000
174+++ ubuntu_sso/qt/reset_password_page.py 2012-03-09 17:35:23 +0000
175@@ -73,6 +73,7 @@
176
177 def initializePage(self):
178 """Extends QWizardPage initializePage method."""
179+ logger.debug('initializePage - About to show ResetPasswordPage')
180 super(ResetPasswordPage, self).initializePage()
181 common.password_default_assistance(self.ui.password_assistance)
182 self.ui.password_assistance.setVisible(False)
183@@ -158,6 +159,8 @@
184
185 def on_password_changed(self, app_name, email):
186 """Let user know that the password was changed."""
187+ logger.info('ResetPasswordPage.on_password_changed for %s, email: %s',
188+ app_name, email)
189 self.hide_overlay()
190 email = unicode(self.wizard().forgotten.ui.email_line_edit.text())
191 self.passwordChanged.emit(email)
192
193=== modified file 'ubuntu_sso/qt/setup_account_page.py'
194--- ubuntu_sso/qt/setup_account_page.py 2012-03-07 18:03:28 +0000
195+++ ubuntu_sso/qt/setup_account_page.py 2012-03-09 17:35:23 +0000
196@@ -31,7 +31,7 @@
197 from PyQt4 import QtGui, QtCore
198
199 from ubuntu_sso import NO_OP
200-from ubuntu_sso.logger import setup_gui_logging
201+from ubuntu_sso.logger import setup_gui_logging, log_call
202 from ubuntu_sso.qt import (
203 LINK_STYLE,
204 build_general_error_message,
205@@ -122,6 +122,7 @@
206
207 def initializePage(self):
208 """Setup UI details."""
209+ logger.debug('initializePage - About to show SetupAccountPage')
210 # Set Setup Account button
211 self.wizard().setOption(QtGui.QWizard.HaveCustomButton3, True)
212 try:
213@@ -157,7 +158,6 @@
214
215 def _set_translated_strings(self):
216 """Set the strings."""
217- logger.debug('SetUpAccountPage._set_translated_strings')
218 # set the translated string
219 title_page = REGISTER_TITLE.format(app_name=self.app_name)
220 self.setTitle(title_page)
221@@ -225,7 +225,6 @@
222
223 def _connect_ui(self):
224 """Set the connection of signals."""
225- logger.debug('SetUpAccountPage._connect_ui')
226 self._set_line_edits_validations()
227
228 self.ui.captcha_view.setPixmap(QtGui.QPixmap())
229@@ -302,11 +301,9 @@
230 self.registerField('email_address', self.ui.email_edit)
231 self.registerField('password', self.ui.password_edit)
232
233+ @log_call(logger.debug)
234 def on_captcha_generated(self, app_name, result):
235 """A new image was generated."""
236- logger.debug('SetUpAccountPage.on_captcha_generated for %r '
237- '(captcha id %r, filename %r).',
238- app_name, result, self.captcha_file)
239 self.captcha_id = result
240 # HACK: First, let me apologize before hand, you can mention my mother
241 # if needed I would do the same (mandel)
242@@ -327,13 +324,13 @@
243
244 def on_captcha_generation_error(self, error, *args, **kwargs):
245 """An error ocurred."""
246- logger.debug('SetUpAccountPage.on_captcha_generation_error')
247+ logger.error('Got error on captcha generation: %s', error)
248 self.show_error(self.app_name, CAPTCHA_LOAD_ERROR)
249 self.on_captcha_refresh_complete()
250
251+ @log_call(logger.error)
252 def on_user_registration_error(self, app_name, error):
253 """Let the user know we could not register."""
254- logger.debug('SetUpAccountPage.on_user_registration_error')
255 # errors are returned as a dict with the data we want to show.
256 msg = error.pop(ERROR_EMAIL, '')
257 if msg:
258@@ -343,10 +340,10 @@
259 self.show_error(self.app_name, error_msg)
260 self._refresh_captcha()
261
262+ @log_call(logger.info)
263 def on_user_registered(self, app_name, email):
264 """Execute when the user did register."""
265 self.hide_overlay()
266- logger.debug('SetUpAccountPage.on_user_registered')
267 email = unicode(self.ui.email_edit.text())
268 self.userRegistered.emit(email)
269
270@@ -406,17 +403,14 @@
271
272 def is_correct_email(self, email_address):
273 """Return if the email is correct."""
274- logger.debug('SetUpAccountPage.is_correct_email')
275 return '@' in email_address
276
277 def is_correct_email_confirmation(self, email_address):
278 """Return that the email is the same."""
279- logger.debug('SetUpAccountPage.is_correct_email_confirmation')
280 return unicode(self.ui.email_edit.text()) == email_address
281
282 def is_correct_password_confirmation(self, password):
283 """Return that the passwords are correct."""
284- logger.debug('SetUpAccountPage.is_correct_password_confirmation')
285 return unicode(self.ui.password_edit.text()) == password
286
287 def focus_changed(self, old, now):
288@@ -505,12 +499,14 @@
289
290 def on_captcha_refreshing(self):
291 """Show overlay when captcha is refreshing."""
292+ logger.info('SetUpAccountPage.on_captcha_refreshing')
293 if self.isVisible():
294 self.show_overlay()
295 self.captcha_received = False
296
297 def on_captcha_refresh_complete(self):
298 """Hide overlay when captcha finished refreshing."""
299+ logger.info('SetUpAccountPage.on_captcha_refresh_complete')
300 self.hide_overlay()
301 self.captcha_received = True
302
303
304=== modified file 'ubuntu_sso/qt/sso_wizard_page.py'
305--- ubuntu_sso/qt/sso_wizard_page.py 2012-03-05 21:18:15 +0000
306+++ ubuntu_sso/qt/sso_wizard_page.py 2012-03-09 17:35:23 +0000
307@@ -33,7 +33,7 @@
308 from twisted.internet import defer
309
310 from ubuntu_sso import main
311-from ubuntu_sso.logger import setup_gui_logging
312+from ubuntu_sso.logger import setup_gui_logging, log_call
313 from ubuntu_sso.qt import PREFERED_UI_SIZE, TITLE_STYLE
314 from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR
315
316@@ -129,6 +129,7 @@
317
318 self.setup_page()
319
320+ @log_call(logger.error)
321 def show_error(self, app_name, message):
322 """Show an error message inside the page."""
323 self.hide_overlay()
324@@ -159,7 +160,7 @@
325 """Setup the widget components."""
326 client = yield main.get_sso_client()
327 self.backend = client.sso_login
328-
329+ logger.info('%r - setup_page, backend is %r.', self, self.backend)
330 self._setup_signals()
331 self._set_translated_strings()
332 self._connect_ui()
333
334=== modified file 'ubuntu_sso/qt/tests/login_u_p.py'
335--- ubuntu_sso/qt/tests/login_u_p.py 2012-01-26 15:34:16 +0000
336+++ ubuntu_sso/qt/tests/login_u_p.py 2012-03-09 17:35:23 +0000
337@@ -39,7 +39,6 @@
338
339 def found(*args):
340 """The result was received."""
341- print "result received", args
342 d.callback(args)
343
344 client.cred_manager.connect_to_signal('CredentialsFound', found)
345@@ -61,7 +60,6 @@
346 yield cleared
347
348 yield client.cred_manager.login_email_password('SUPER', args)
349- print "called ok"
350 yield d
351
352 yield client.disconnect()
353
354=== modified file 'ubuntu_sso/qt/tests/show_gui.py'
355--- ubuntu_sso/qt/tests/show_gui.py 2012-02-10 17:18:22 +0000
356+++ ubuntu_sso/qt/tests/show_gui.py 2012-03-09 17:35:23 +0000
357@@ -46,7 +46,6 @@
358
359 def found(*args):
360 """The result was received."""
361- print "result received", args
362 d.callback(args)
363
364 client.cred_manager.connect_to_signal('CredentialsFound', found)
365@@ -62,7 +61,6 @@
366 TC_URL_KEY: u'http://www.google.com/',
367 UI_EXECUTABLE_KEY: 'ubuntu-sso-login-gtk',
368 })
369- print "called ok"
370 yield d
371
372 yield client.disconnect()
373
374=== modified file 'ubuntu_sso/qt/ubuntu_sso_wizard.py'
375--- ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-03-05 21:08:40 +0000
376+++ ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-03-09 17:35:23 +0000
377@@ -141,6 +141,8 @@
378
379 def _go_back_to_page(self, page):
380 """Move back until it reaches the 'page'."""
381+ logger.debug('Moving back from page: %s, to page: %s',
382+ self.currentPage(), page)
383 page_id = self._pages[page]
384 visited_pages = self.visitedPages()
385 for index in reversed(visited_pages):
386@@ -150,12 +152,16 @@
387
388 def _move_to_reset_password_page(self):
389 """Move to the reset password page wizard."""
390+ logger.debug('Moving to ResetPasswordPage from: %s',
391+ self.currentPage())
392 self._next_id = self.reset_password_page_id
393 self.next()
394 self._next_id = -1
395
396 def _move_to_email_verification_page(self, email):
397 """Move to the email verification page wizard."""
398+ logger.debug('Moving to EmailVerificationPage from: %s',
399+ self.currentPage())
400 self._next_id = self.email_verification_page_id
401 self.email_verification.email = unicode(email)
402 self.email_verification.password = self.currentPage().password
403@@ -164,18 +170,24 @@
404
405 def _move_to_setup_account_page(self):
406 """Move to the setup account page wizard."""
407+ logger.debug('Moving to SetupAccountPage from: %s',
408+ self.currentPage())
409 self._next_id = self.setup_account_page_id
410 self.next()
411 self._next_id = -1
412
413 def _move_to_login_page(self):
414 """Move to the login page wizard."""
415+ logger.debug('Moving to CurrentUserSignInPage from: %s',
416+ self.currentPage())
417 self._next_id = self.current_user_page_id
418 self.next()
419 self._next_id = -1
420
421 def _move_to_success_page(self):
422 """Move to the success page wizard."""
423+ logger.debug('Moving to SuccessPage from: %s',
424+ self.currentPage())
425 self._next_id = self.success_page_id
426 self.next()
427 self.setButtonLayout([
428@@ -188,6 +200,8 @@
429
430 def _move_to_forgotten_page(self):
431 """Move to the forgotten page wizard."""
432+ logger.debug('Moving to ForgottenPasswordPage from: %s',
433+ self.currentPage())
434 self._next_id = self.forgotten_password_page_id
435 self.next()
436 self._next_id = -1

Subscribers

People subscribed via source and target branches