changeset 46:997d0c8c174f draft

Default for the launch callable should be not to log.
author David Barts <n5jrn@me.com>
date Thu, 30 May 2019 16:36:43 -0700
parents 969f515b505b
children 879ec681f7e3
files launch tincan.py
diffstat 2 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/launch	Thu May 30 14:44:09 2019 -0700
+++ b/launch	Thu May 30 16:36:43 2019 -0700
@@ -7,6 +7,7 @@
 
 import os, sys
 from argparse import ArgumentParser
+import logging
 from tincan import launch, ENCODING
 
 # V a r i a b l e s
@@ -26,7 +27,10 @@
 opt("directory", default=".", help="directory to serve", nargs='?')
 opt("path", default="/", help="URL path to serve", nargs='?')
 args = parser.parse_args(sys.argv[1:])
-app, errors = launch(fsroot=args.directory, urlroot=args.path, debug=args.debug,
+mylog = logging.getLogger(MYNAME)
+mylog.addHandler(logging.StreamHandler())
+mylog.setLevel(logging.DEBUG if args.debug else logging.INFO)
+app, errors = launch(fsroot=args.directory, urlroot=args.path, logger=mylog,
     encoding=args.encoding, static=args.static)
 if errors:
     action = "continuing" if args.force else "aborting"
--- a/tincan.py	Thu May 30 14:44:09 2019 -0700
+++ b/tincan.py	Thu May 30 16:36:43 2019 -0700
@@ -21,7 +21,6 @@
 from threading import Lock
 import time
 import urllib
-import uuid
 
 import bottle
 
@@ -883,16 +882,15 @@
             elif S_ISDIR(etype):
                 self._launch(subdir + [entry])
 
-def launch(fsroot=None, urlroot='/', logger=None, debug=False,
-    encoding=ENCODING, static=False, multithread=True):
+_BITBUCKET = logging.getLogger(__name__)
+_BITBUCKET.addHandler(logging.NullHandler)
+
+def launch(fsroot=None, urlroot='/', logger=_BITBUCKET, encoding=ENCODING,
+    static=False, multithread=True):
     """
     Launch and return a TinCan webapp. Does not run the app; it is the
     caller's responsibility to call app.run()
     """
-    if logger is None:
-        logger = logging.getLogger("{0!s}-{1!s}".format(__name__, uuid.uuid1()))
-        logger.addHandler(logging.StreamHandler())
-    logger.setLevel(logging.DEBUG if debug else logging.INFO)
     if fsroot is None:
         fsroot = os.getcwd()
     launcher = _Launcher(fsroot, urlroot, multithread)