FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Edubuntu User

 
 
LinkBack Thread Tools
 
Old 01-04-2011, 12:36 PM
Ales Kozumplik
 
Default logging: log_method_return() for devicetree.getDeviceByName()

Together with identing the depth of the getDeviceByName() call, this aims
to make storage.log easier to read.
---
pyanaconda/anaconda_log.py | 27 +++++++++++++++++++++++----
pyanaconda/storage/devicetree.py | 12 +++++++-----
2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/pyanaconda/anaconda_log.py b/pyanaconda/anaconda_log.py
index c570024..04dea8d 100644
--- a/pyanaconda/anaconda_log.py
+++ b/pyanaconda/anaconda_log.py
@@ -58,12 +58,23 @@ def setHandlersLevel(logger, level):
map(lambda hdlr: hdlr.setLevel(level),
filter (lambda hdlr: hasattr(hdlr, "autoSetLevel") and hdlr.autoSetLevel, logger.handlers))

-def log_method_call(d, *args, **kwargs):
- classname = d.__class__.__name__
+def function_name_and_depth():
+ IGNORED_FUNCS = ["function_name_and_depth",
+ "log_method_call",
+ "log_method_return"]
stack = inspect.stack()
- methodname = stack[1][3]

- spaces = len(stack) * ' '
+ for i, frame in enumerate(stack):
+ methodname = frame[3]
+ if methodname not in IGNORED_FUNCS:
+ return (methodname, len(stack) - i)
+
+ return ("unknown function?", 0)
+
+def log_method_call(d, *args, **kwargs):
+ classname = d.__class__.__name__
+ (methodname, depth) = function_name_and_depth()
+ spaces = depth * ' '
fmt = "%s%s.%s:"
fmt_args = [spaces, classname, methodname]

@@ -77,6 +88,14 @@ def log_method_call(d, *args, **kwargs):

logging.getLogger("storage").debug(fmt % tuple(fmt_args))

+def log_method_return(d, retval):
+ classname = d.__class__.__name__
+ (methodname, depth) = function_name_and_depth()
+ spaces = depth * ' '
+ fmt = "%s%s.%s returned %s"
+ fmt_args = (spaces, classname, methodname, retval)
+ logging.getLogger("storage").debug(fmt % fmt_args)
+
class AnacondaSyslogHandler(SysLogHandler):
def __init__(self,
address=('localhost', SYSLOG_UDP_PORT),
diff --git a/pyanaconda/storage/devicetree.py b/pyanaconda/storage/devicetree.py
index e500520..b90a130 100644
--- a/pyanaconda/storage/devicetree.py
+++ b/pyanaconda/storage/devicetree.py
@@ -40,7 +40,7 @@ import devicelibs.loop
from udev import *
from pyanaconda import iutil
from pyanaconda import tsort
-from pyanaconda.anaconda_log import log_method_call
+from pyanaconda.anaconda_log import log_method_call, log_method_return
import parted
import _ped

@@ -1860,8 +1860,9 @@ class DeviceTree(object):
return found

def getDeviceByName(self, name):
- log.debug("looking for device '%s'..." % name)
+ log_method_call(self, name=name)
if not name:
+ log_method_return(self, None)
return None

found = None
@@ -1874,12 +1875,13 @@ class DeviceTree(object):
found = device
break

- log.debug("found %s" % found)
+ log_method_return(self, found)
return found

def getDeviceByPath(self, path):
- log.debug("looking for device '%s'..." % path)
+ log_method_call(self, path=path)
if not path:
+ log_method_return(self, None)
return None

found = None
@@ -1892,7 +1894,7 @@ class DeviceTree(object):
found = device
break

- log.debug("found %s" % found)
+ log_method_return(self, found)
return found

def getDevicesByType(self, device_type):
--
1.7.3.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 09:36 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org