From 07d71c14e51e3333d2823bb0ea28b38af9c22949 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 14 Feb 2016 16:07:53 +0100 Subject: Use named logger --- httpfs/__init__.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'httpfs') diff --git a/httpfs/__init__.py b/httpfs/__init__.py index 9a2d2c9..1b4ede3 100644 --- a/httpfs/__init__.py +++ b/httpfs/__init__.py @@ -13,6 +13,8 @@ import fuse import requests +logger = logging.getLogger(__name__) + class Config: mountpoint = None timeout = None @@ -41,7 +43,7 @@ class Path: if type(pathElement) == bytes: pathElement = pathElement.decode('utf-8') p = clazz(parent, unquote(pathElement)) - logging.info("created {} '{}' referencing {}".format( + logger.info("created {} '{}' referencing {}".format( clazz.__name__, p.name, p.buildUrl())) return p @@ -56,7 +58,7 @@ class File(Path): def init(self): url = self.buildUrl() - logging.info("File url={} name={}".format(url, self.name)) + logger.info("File url={} name={}".format(url, self.name)) r = self.getSession().head(url, timeout=Config.timeout, allow_redirects=True) r.close() @@ -72,7 +74,7 @@ class File(Path): self.size = int(r.headers['content-length']) self.lastModified = time.mktime(parsedate(r.headers['last-modified'])) - logging.info("File initialized url={} name={}".format(url, self.name)) + logger.info("File initialized url={} name={}".format(url, self.name)) self.initialized = True def get(self, size, offset): @@ -81,15 +83,15 @@ class File(Path): url = self.buildUrl() bytesRange = '{}-{}'.format(offset, min(self.size, offset + size - 1)) headers = {'range': 'bytes=' + bytesRange} - logging.info("File.get url={} range={}".format(url, bytesRange)) + logger.info("File.get url={} range={}".format(url, bytesRange)) r = self.getSession().get(url, headers=headers, timeout=Config.timeout) r.close() if r.status_code == 200 or r.status_code == 206: d = r.content - logging.info("Received {} bytes".format(len(d))) + logger.info("Received {} bytes".format(len(d))) if len(d) > size: errormsg = "size {} > than expected {}".format(len(d), size) - logging.error(errormsg) + logger.error(errormsg) raise fuse.FuseOSError(EIO) return d else: @@ -114,11 +116,11 @@ class Directory(Path): def init(self): url = self.buildUrl() + "/" - logging.info("Directory url={} name={}".format(url, self.name)) + logger.info("Directory url={} name={}".format(url, self.name)) r = self.getSession().get(url, stream=True, timeout=Config.timeout) if r.status_code >= 400 and r.status_code <= 499: self.mode = 0o000 - logging.info("Directory is 4xx {}".format(url)) + logger.info("Directory is 4xx {}".format(url)) r.close() self.initialized = True return @@ -138,7 +140,7 @@ class Directory(Path): self.entries.update(parser.entries) r.close() - logging.info("Diretory loaded {}".format(url)) + logger.info("Diretory loaded {}".format(url)) self.initialized = True def getAttr(self): @@ -162,7 +164,7 @@ class Server(Directory): elif Config.verify == "system": self.session.verify = Config.system_ca elif Config.verify == "none": - logging.warning("SSL Verification disabled!") + logger.warning("SSL Verification disabled!") self.session.verify = False else: raise SystemExit("Invalid value for ssl verification") @@ -236,23 +238,23 @@ class Httpfs(fuse.LoggingMixIn, fuse.Operations): for machine in netrc.netrc().hosts.keys(): yield (machine, Server(parent, machine)) except IOError as e: - logging.warning("No .netrc file found, no default machines") + logger.warning("No .netrc file found, no default machines") def getattr(self, path, fh=None): - logging.debug("getattr path={}".format(path)) + logger.debug("getattr path={}".format(path)) try: entry = self._getPath(path) if entry: return entry.getAttr() except Exception as e: - logging.exception("Error in getattr(%s)", path) + logger.exception("Error in getattr(%s)", path) raise fuse.FuseOSError(EHOSTUNREACH) raise fuse.FuseOSError(ENOENT) def _getPath(self, path): """ map path to self.root tree a path is build like ///""" - logging.debug("getPath path={}".format(path)) + logger.debug("getPath path={}".format(path)) if path == "/": return self.root @@ -261,7 +263,7 @@ class Httpfs(fuse.LoggingMixIn, fuse.Operations): schema, *p = path[1:].split("/") if schema not in self.root.entries: - logging.debug("schema %s not in root.entries", schema) + logger.debug("schema %s not in root.entries", schema) return None prevEntry = self.root.entries[schema] if p == []: @@ -293,18 +295,18 @@ class Httpfs(fuse.LoggingMixIn, fuse.Operations): r = d.getSession().head(url, timeout=Config.timeout, allow_redirects=True) if r.status_code == 200: - logging.info("Create directory for path: {} " + logger.info("Create directory for path: {} " "at: {}".format(path, url)) prevEntry.entries[lastElement] = d else: - logging.info("Path not found ({}): {} for {}".format( + logger.info("Path not found ({}): {} for {}".format( r.status_code, path, url)) return None return prevEntry.entries[lastElement] def readdir(self, path, fh): try: - logging.debug("readdir path=%s", path) + logger.debug("readdir path=%s", path) entry = self._getPath(path) if not entry: raise fuse.FuseOSError(EBADF) @@ -317,7 +319,7 @@ class Httpfs(fuse.LoggingMixIn, fuse.Operations): (it.name, it.getAttr(), 0) for it in entry.entries.values() ] except Exception as e: - logging.exception("Error in readdir(%s)", path) + logger.exception("Error in readdir(%s)", path) raise fuse.FuseOSError(EIO) def read(self, path, size, offset, fh): -- cgit v1.2.1