Replace self.pl.exception with self.exception
New function is checking for self.pl being set before using logger and also removes the need of specifying explicit prefix="powerline". Conflicts: powerline/__init__.py
This commit is contained in:
parent
201175d368
commit
82e2ea10c4
|
@ -266,7 +266,7 @@ class Powerline(object):
|
||||||
try:
|
try:
|
||||||
Renderer = __import__(self.renderer_module, fromlist=['renderer']).renderer
|
Renderer = __import__(self.renderer_module, fromlist=['renderer']).renderer
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.pl.exception('Failed to import renderer module: {0}', str(e))
|
self.exception('Failed to import renderer module: {0}', str(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Renderer updates configuration file via segments’ .startup thus it
|
# Renderer updates configuration file via segments’ .startup thus it
|
||||||
|
@ -275,7 +275,7 @@ class Powerline(object):
|
||||||
try:
|
try:
|
||||||
renderer = Renderer(**self.renderer_options)
|
renderer = Renderer(**self.renderer_options)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.pl.exception('Failed to construct renderer object: {0}', str(e))
|
self.exception('Failed to construct renderer object: {0}', str(e))
|
||||||
if not hasattr(self, 'renderer'):
|
if not hasattr(self, 'renderer'):
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
|
@ -393,8 +393,7 @@ class Powerline(object):
|
||||||
try:
|
try:
|
||||||
self.create_renderer(**create_renderer_kwargs)
|
self.create_renderer(**create_renderer_kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.pl:
|
self.exception('Failed to create renderer: {0}', str(e))
|
||||||
self.pl.exception('Failed to create renderer: {0}', str(e), prefix='powerline')
|
|
||||||
if hasattr(self, 'renderer'):
|
if hasattr(self, 'renderer'):
|
||||||
with self.cr_kwargs_lock:
|
with self.cr_kwargs_lock:
|
||||||
self.create_renderer_kwargs.clear()
|
self.create_renderer_kwargs.clear()
|
||||||
|
@ -412,8 +411,15 @@ class Powerline(object):
|
||||||
self.update_renderer()
|
self.update_renderer()
|
||||||
return self.renderer.render(*args, **kwargs)
|
return self.renderer.render(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.pl:
|
try:
|
||||||
self.pl.exception('Failed to render: {0}', str(e), prefix='powerline')
|
self.exception('Failed to render: {0}', str(e))
|
||||||
|
except Exception as e:
|
||||||
|
# Updates e variable to new value, masking previous one.
|
||||||
|
# Normally it is the same exception (due to raise in case pl is
|
||||||
|
# unset), but it may also show error in logger. Note that latter
|
||||||
|
# is not logged by logger for obvious reasons, thus this also
|
||||||
|
# prevents us from seeing logger traceback.
|
||||||
|
pass
|
||||||
return FailedUnicode(safe_unicode(e))
|
return FailedUnicode(safe_unicode(e))
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
@ -455,3 +461,9 @@ class Powerline(object):
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
|
def exception(self, msg, prefix='powerline', *args, **kwargs):
|
||||||
|
if self.pl:
|
||||||
|
return self.pl.exception(msg, prefix=prefix, *args, **kwargs)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
Loading…
Reference in New Issue