Commit 147a2b67 by rfkelly0

allow uniform use of logging throughout the module

parent 7ca85974
......@@ -45,3 +45,16 @@ import os
SEEK_CUR = os.SEEK_CUR
SEEK_END = os.SEEK_END
SEEK_SET = os.SEEK_SET
# Allow clean use of logging throughout the lib
import logging as _logging
class _NullHandler(_logging.Handler):
def emit(self,record):
pass
_logging.getLogger("fs").addHandler(_NullHandler())
def getLogger(name):
"""Get a logger object for use within the pyfilesystem library."""
assert name.startswith("fs.")
return _logging.getLogger(name)
......@@ -31,6 +31,7 @@ import cookielib
import fnmatch
import xml.dom.pulldom
import fs
from fs.base import *
from fs.path import *
from fs.errors import *
......@@ -40,8 +41,7 @@ from fs.contrib.davfs.util import *
from fs.contrib.davfs import xmlobj
from fs.contrib.davfs.xmlobj import *
import logging
logger = logging.getLogger("fs.contrib.davfs")
logger = fs.getLogger("fs.contrib.davfs")
import errno
_RETRYABLE_ERRORS = [errno.EADDRINUSE]
......@@ -236,7 +236,7 @@ class DAVFS(FS):
except KeyError:
msg = "unsupported protocol: '%s'" % (url.scheme,)
raise RemoteConnectionError(msg=msg)
#logger.debug("DAVFS >REQ %s %s/%s",method,url.hostname,url.path)
logger.debug("DAVFS >REQ %s %s/%s",method,url.hostname,url.path)
con = ConClass(url.hostname,url.port,timeout=self.timeout)
self._add_connection(con)
try:
......@@ -257,11 +257,11 @@ class DAVFS(FS):
resp = con.getresponse()
self._cookiejar.extract_cookies(FakeResp(resp),FakeReq(con,url.scheme,url.path))
except Exception, e:
#logger.exception("DAVFS <ERR %s %s/%s",method,url.hostname,url.path)
logger.exception("DAVFS <ERR %s %s/%s",method,url.hostname,url.path)
self._del_connection(con)
raise
else:
#logger.debug("DAVFS <RESP %s %s %s/%s",resp.status,method,url.hostname,url.path)
logger.debug("DAVFS <RESP %s %s %s/%s",resp.status,method,url.hostname,url.path)
old_close = resp.close
def new_close():
old_close()
......
......@@ -54,6 +54,7 @@ import stat as statinfo
import logging
from logging import DEBUG, INFO, ERROR, CRITICAL
import fs
import fs.errors as errors
from fs.path import abspath, relpath, normpath, dirname, pathjoin
from fs import FS, NullFile, _thread_synchronize_default, SEEK_END
......@@ -63,7 +64,7 @@ from fs.base import fnmatch, NoDefaultMeta
from util import TahoeUtil
from connection import Connection
logger = logging.getLogger('fs.tahoefs')
logger = fs.getLogger('fs.tahoefs')
def _fix_path(func):
"""Method decorator for automatically normalising paths."""
......
......@@ -83,6 +83,10 @@ else:
from ctypes.wintypes import LPCWSTR, WCHAR
kernel32 = ctypes.windll.kernel32
import logging
logger = logging.getLogger("fs.expose.dokan")
# Options controlling the behaiour of the Dokan filesystem
DOKAN_OPTION_DEBUG = 1
DOKAN_OPTION_STDERR = 2
......@@ -139,6 +143,7 @@ FILETIME_UNIX_EPOCH = 116444736000000000
def _debug(*args):
#print >>sys.stderr, args; sys.stderr.flush()
#logger.debug(map(str,args))
pass
......
......@@ -54,7 +54,10 @@ class DirMount(object):
self.fs = fs
def __str__(self):
return "Mount point: %s"%self.path
return "Mount point: <%s,%s>" % (self.path,self.fs,)
__repr__ = __str__
def __unicode__(self):
return unicode(str(self))
class FileMount(object):
......@@ -83,7 +86,7 @@ class MountFS(FS):
self.mount_tree = PathMap()
def __str__(self):
return "<MountFS>"
return "<%s [%s]>" % (self.__class__.__name__,self.mount_tree.items(),)
__repr__ = __str__
......
......@@ -496,6 +496,9 @@ class PathMap(object):
for subk in self.iterkeys(k,subm):
yield subk
def __iter__(self):
return self.iterkeys()
def keys(self,root="/"):
return list(self.iterkeys(root))
......@@ -558,6 +561,7 @@ class PathMap(object):
def names(self,root="/"):
return list(self.iternames(root))
_wild_chars = frozenset('*?[]!{}')
def iswildcard(path):
"""Check if a path ends with a wildcard
......
......@@ -39,9 +39,6 @@ from fs.local_functools import wraps
from fs.filelike import StringIO, SpooledTemporaryFile, FileWrapper
from fs import SEEK_SET, SEEK_CUR, SEEK_END
import logging
logger = logging.getLogger("fs.remote")
_SENTINAL = object()
......@@ -595,9 +592,7 @@ class CacheFSMixin(WrapFS):
if not ci.has_full_info:
raise KeyError
info = ci.info
logger.debug("GOT INFO FROM CACHE: %r",path)
except KeyError:
logger.debug("INFO WASN'T IN CACHE: %r",path)
info = super(CacheFSMixin,self).getinfo(path)
self.__set_cached_info(path,CachedInfo(info))
return info
......
......@@ -466,6 +466,7 @@ def wrap_fs_methods(decorator, cls=None, exclude=[]):
wrap_fs_methods.method_names = ["open","exists","isdir","isfile","listdir",
"makedir","remove","setcontents","removedir","rename","getinfo","copy",
"move","copydir","movedir","close","getxattr","setxattr","delxattr",
"listxattrs","getsyspath","createfile", "hasmeta", "getmeta"]
"listxattrs","getsyspath","createfile", "hasmeta", "getmeta","listdirinfo",
"ilistdir","ilistdirinfo"]
......@@ -38,9 +38,10 @@ import logging
from logging import DEBUG, INFO, ERROR, CRITICAL
import sys
import fs
from fs.errors import FSError
logger = logging.getLogger('fs.debugfs')
logger = fs.getLogger('fs.debugfs')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment