Merge lp:~dobey/ubuntuone-client/oauth-log-fixes into lp:ubuntuone-client

Proposed by dobey
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 241
Merged at revision: not available
Proposed branch: lp:~dobey/ubuntuone-client/oauth-log-fixes
Merge into: lp:ubuntuone-client
Diff against target: 164 lines
5 files modified
bin/ubuntuone-client-applet (+3/-5)
ubuntuone/oauthdesktop/auth.py (+14/-14)
ubuntuone/oauthdesktop/logger.py (+17/-3)
ubuntuone/oauthdesktop/main.py (+1/-3)
ubuntuone/syncdaemon/logger.py (+1/-1)
To merge this branch: bzr merge lp:~dobey/ubuntuone-client/oauth-log-fixes
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Rick McBride (community) Approve
Review via email: mp+13017@code.launchpad.net

Commit message

Rotate the oauth log and cap at 1MB
Change a few logger.debug messages to logger.error
Clean up the usage of callback_error in the oauth process

To post a comment you must log in.
Revision history for this message
Rick McBride (rmcbride) wrote :

Other than the below, this looks good.
== Python Lint Notices ==

./ubuntuone/oauthdesktop/auth.py:
    261: undefined name 'e'

review: Approve
241. By dobey

Fix typo: should be errors instead of e

Revision history for this message
Guillermo Gonzalez (verterok) :
review: Approve
242. By dobey

Change log level to INFO
Change startup version logging to info level

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/ubuntuone-client-applet'
--- bin/ubuntuone-client-applet 2009-10-02 17:55:29 +0000
+++ bin/ubuntuone-client-applet 2009-10-08 13:35:16 +0000
@@ -45,9 +45,7 @@
45from urllib import quote45from urllib import quote
4646
47from ubuntuone.oauthdesktop.logger import setupLogging47from ubuntuone.oauthdesktop.logger import setupLogging
48setupLogging()48logger = setupLogging("UbuntuOne.Client.Applet")
49import logging
50logger = logging.getLogger("UbuntuOne.Client.Applet")
5149
52DBusGMainLoop(set_as_default=True)50DBusGMainLoop(set_as_default=True)
5351
@@ -96,8 +94,8 @@
96 login = Login(dbus.service.BusName(DBUS_IFACE_AUTH_NAME,94 login = Login(dbus.service.BusName(DBUS_IFACE_AUTH_NAME,
97 bus=dbus.SessionBus()))95 bus=dbus.SessionBus()))
9896
99 logger.debug(_("Starting Ubuntu One client version %s") %97 logger.info(_("Starting Ubuntu One client version %s") %
100 clientdefs.VERSION)98 clientdefs.VERSION)
10199
102 # Whether or not we are authorized100 # Whether or not we are authorized
103 self.is_authorized = False101 self.is_authorized = False
104102
=== modified file 'ubuntuone/oauthdesktop/auth.py'
--- ubuntuone/oauthdesktop/auth.py 2009-10-07 15:09:56 +0000
+++ ubuntuone/oauthdesktop/auth.py 2009-10-08 13:35:16 +0000
@@ -37,9 +37,7 @@
37from twisted.web import server, resource37from twisted.web import server, resource
3838
39from ubuntuone.oauthdesktop.logger import setupLogging39from ubuntuone.oauthdesktop.logger import setupLogging
40setupLogging()40logger = setupLogging("UbuntuOne.OAuthDesktop.auth")
41import logging
42logger = logging.getLogger("UbuntuOne.OAuthDesktop.auth")
4341
4442
45class NoAccessToken(Exception):43class NoAccessToken(Exception):
@@ -144,6 +142,13 @@
144 'oauth-consumer-key':142 'oauth-consumer-key':
145 self.consumer.key})143 self.consumer.key})
146144
145 def _forward_error_callback(self, error):
146 """Forward an error through callback_error()"""
147 if self.callback_error:
148 self.callback_error(str(error))
149 else:
150 raise error
151
147 def get_access_token(self):152 def get_access_token(self):
148 """Get the access token from the keyring.153 """Get the access token from the keyring.
149154
@@ -229,11 +234,8 @@
229 fp = opener.open(oauth_request.http_url, oauth_request.to_postdata())234 fp = opener.open(oauth_request.http_url, oauth_request.to_postdata())
230 data = fp.read()235 data = fp.read()
231 except IOError, e:236 except IOError, e:
232 if self.callback_error:237 self._forward_error_callback(e)
233 self.callback_error(str(e))238 return
234 return
235 else:
236 raise e
237 239
238 # we deliberately trap anything that might go wrong when parsing the240 # we deliberately trap anything that might go wrong when parsing the
239 # token, because we do not want this to explicitly fail241 # token, because we do not want this to explicitly fail
@@ -243,8 +245,9 @@
243 logger.debug("Token successfully requested")245 logger.debug("Token successfully requested")
244 return out_token246 return out_token
245 except:247 except:
246 logger.debug("Token was not successfully retrieved: data was '%s'",248 logger.error("Token was not successfully retrieved: data was '%s'",
247 data)249 data)
250 self._forward_error_callback(oauth.OAuthError(data))
248251
249 def open_in_browser(self, url):252 def open_in_browser(self, url):
250 """Open the given URL in the user's web browser."""253 """Open the given URL in the user's web browser."""
@@ -255,10 +258,7 @@
255 if p.returncode != 0:258 if p.returncode != 0:
256 errors = "".join(p.stderr.readlines())259 errors = "".join(p.stderr.readlines())
257 if errors != "":260 if errors != "":
258 if self.callback_error is not None:261 self._forward_error_callback(IOError(errors))
259 self.callback_error(errors)
260 else:
261 raise Exception(errors)
262262
263 def acquire_access_token_if_online(self, description=None, store=False):263 def acquire_access_token_if_online(self, description=None, store=False):
264 """Check to see if we are online before trying to acquire"""264 """Check to see if we are online before trying to acquire"""
@@ -377,7 +377,7 @@
377 logger.debug("Retrieving access token from OAuth")377 logger.debug("Retrieving access token from OAuth")
378 access_token = self.make_token_request(oauth_request)378 access_token = self.make_token_request(oauth_request)
379 if not access_token:379 if not access_token:
380 logger.debug("Failed to get access token.")380 logger.error("Failed to get access token.")
381 if self.callback_denied is not None:381 if self.callback_denied is not None:
382 self.callback_denied()382 self.callback_denied()
383 else:383 else:
384384
=== modified file 'ubuntuone/oauthdesktop/logger.py'
--- ubuntuone/oauthdesktop/logger.py 2009-06-26 17:01:42 +0000
+++ ubuntuone/oauthdesktop/logger.py 2009-10-08 13:35:16 +0000
@@ -20,6 +20,8 @@
20import logging20import logging
21import xdg.BaseDirectory21import xdg.BaseDirectory
2222
23from logging.handlers import RotatingFileHandler
24
23home = xdg.BaseDirectory.xdg_cache_home25home = xdg.BaseDirectory.xdg_cache_home
24LOGFOLDER = os.path.join(home, 'ubuntuone', 'log')26LOGFOLDER = os.path.join(home, 'ubuntuone', 'log')
25# create log folder if it doesn't exists27# create log folder if it doesn't exists
@@ -28,7 +30,19 @@
2830
29LOGFILENAME = os.path.join(LOGFOLDER, 'oauth-login.log')31LOGFILENAME = os.path.join(LOGFOLDER, 'oauth-login.log')
3032
31def setupLogging():33# Only log this level and above
34LOG_LEVEL = logging.INFO
35
36root_formatter = logging.Formatter(
37 fmt="%(asctime)s:%(msecs)s %(name)s %(message)s")
38root_handler = RotatingFileHandler(LOGFILENAME, maxBytes=1048576,
39 backupCount=1)
40root_handler.setLevel(LOG_LEVEL)
41
42def setupLogging(log_domain):
32 """Create basic logger to set filename"""43 """Create basic logger to set filename"""
33 logging.basicConfig(level=logging.DEBUG, filename=LOGFILENAME,44 logger = logging.getLogger(log_domain)
34 format="%(asctime)s:%(msecs)s %(name)s %(message)s")45 logger.propagate = False
46 logger.setLevel(LOG_LEVEL)
47 logger.addHandler(root_handler)
48 return logger
3549
=== modified file 'ubuntuone/oauthdesktop/main.py'
--- ubuntuone/oauthdesktop/main.py 2009-09-08 13:28:01 +0000
+++ ubuntuone/oauthdesktop/main.py 2009-10-08 13:35:16 +0000
@@ -34,9 +34,7 @@
34from twisted.internet.threads import deferToThread34from twisted.internet.threads import deferToThread
3535
36from ubuntuone.oauthdesktop.logger import setupLogging36from ubuntuone.oauthdesktop.logger import setupLogging
37setupLogging()37logger = setupLogging("UbuntuOne.OAuthDesktop.main")
38import logging
39logger = logging.getLogger("UbuntuOne.OAuthDesktop.main")
4038
41DBusGMainLoop(set_as_default=True)39DBusGMainLoop(set_as_default=True)
4240
4341
=== modified file 'ubuntuone/syncdaemon/logger.py'
--- ubuntuone/syncdaemon/logger.py 2009-08-29 01:16:01 +0000
+++ ubuntuone/syncdaemon/logger.py 2009-10-08 13:35:16 +0000
@@ -33,7 +33,7 @@
33# extra levels33# extra levels
34# be more verbose than logging.DEBUG(10)34# be more verbose than logging.DEBUG(10)
35TRACE = 535TRACE = 5
36# info that we always want to log (logging.ERROR+1)36# info that we almost always want to log (logging.ERROR - 1)
37NOTE = logging.ERROR - 137NOTE = logging.ERROR - 1
3838
39# map names to the extra levels39# map names to the extra levels

Subscribers

People subscribed via source and target branches