[27525] in Source-Commits
python-afs commit: Add logging support to package
daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Tue Nov 12 18:27:55 2013
Date: Tue, 12 Nov 2013 18:27:48 -0500
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201311122327.rACNRmG6018684@drugstore.mit.edu>
To: source-commits@MIT.EDU
https://github.com/mit-athena/python-afs/commits/af11d3ebc1d6eae35d96a75d349755984653db09
commit af11d3ebc1d6eae35d96a75d349755984653db09
Author: Jonathan Reed <jdreed@mit.edu>
Date: Wed Oct 30 15:27:58 2013 -0400
Add logging support to package
Add support for the Python logging package, with separate loggers
for each submodule.
Use this new logging support to attempt to complain when IP
address conversion fails in _whereis, rather than simply giving up.
afs/__init__.py | 5 +++++
afs/_fs.pyx | 8 +++++---
afs/_util.pyx | 10 ++++++++++
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/afs/__init__.py b/afs/__init__.py
index e69de29..723cd47 100644
--- a/afs/__init__.py
+++ b/afs/__init__.py
@@ -0,0 +1,5 @@
+import logging
+
+# Basic logging support for this package.
+# Add a NullHandler to avoid "No handlers could be found" error
+logging.getLogger('afs').addHandler(logging.NullHandler())
diff --git a/afs/_fs.pyx b/afs/_fs.pyx
index 38f8dc5..7642cae 100644
--- a/afs/_fs.pyx
+++ b/afs/_fs.pyx
@@ -2,6 +2,9 @@ from afs._util cimport *
from afs._util import pyafs_error
import socket
import struct
+import logging
+
+log = logging.getLogger('afs._fs')
__all__ = ['whichcell',
'_lsmount',
@@ -107,7 +110,6 @@ def _whereis(char* path):
break
try:
py_result.append(socket.inet_ntoa(struct.pack('!L', socket.htonl(hosts[j]))))
- except:
- # Oh well
- pass
+ except Exception as e:
+ log.warning("Attempt to convert %d to IP address raised %s: %s", hosts[j], e.__class__.__name__, e)
return py_result
diff --git a/afs/_util.pyx b/afs/_util.pyx
index 8ddd721..4879e86 100644
--- a/afs/_util.pyx
+++ b/afs/_util.pyx
@@ -3,6 +3,9 @@ General PyAFS utilities, such as error handling
"""
import sys
+import logging
+
+log = logging.getLogger('afs._util')
# otherwise certain headers are unhappy
cdef extern from "netinet/in.h": pass
@@ -18,10 +21,13 @@ cdef extern int pioctl_read(char *path, afs_int32 op, void *outbuffer,
unsigned short size, afs_int32 follow) except -1:
cdef ViceIoctl blob
cdef afs_int32 code
+ log.debug("pioctl_read() on %s with operation %d and size %d",
+ path, op, size)
blob.in_size = 0
blob.out_size = size
blob.out = outbuffer
code = pioctl(path, op, &blob, follow)
+ log.debug("pioctl_read() returned %d", code)
# This might work with the rest of OpenAFS, but I'm not convinced
# the rest of it is consistent
if code == -1:
@@ -39,12 +45,16 @@ cdef extern int pioctl_write(char *path, afs_int32 op, char *inbuffer,
cdef afs_int32 code
blob.cin = inbuffer
blob.in_size = 1 + strlen(inbuffer)
+ log.debug("pioctl_write() on %s with operation %d, and input '%s'",
+ path, op, inbuffer)
if outbuffer == NULL:
+ log.debug("No output desired from pioctl_write()")
blob.out_size = 0
else:
blob.out_size = AFS_PIOCTL_MAXSIZE
blob.out = outbuffer
code = pioctl(path, op, &blob, follow)
+ log.debug("pioctl_write() returned %d", code)
# This might work with the rest of OpenAFS, but I'm not convinced
# the rest of it is consistent
if code == -1: