quarrying 3 лет назад
Родитель
Сommit
33812e4dbd
3 измененных файлов с 29 добавлено и 3 удалено
  1. 27 1
      khandy/utils_others.py
  2. 1 1
      khandy/version.py
  3. 1 1
      setup.py

+ 27 - 1
khandy/utils_others.py

@@ -76,4 +76,30 @@ class ContextTimer(object):
     def enter(self):
         """Manually trigger enter"""
         self.__enter__()
-        
+        
+
+def set_logger(filename, level=logging.INFO, logger_name=None):
+    logger = logging.getLogger(logger_name) 
+    logger.setLevel(level)
+    
+    # Never mutate (insert/remove elements) the list you're currently iterating on. 
+    # If you need, make a copy.
+    for handler in logger.handlers[:]:
+        if isinstance(handler, logging.FileHandler):
+            logger.removeHandler(handler)
+        # FileHandler is subclass of StreamHandler, so isinstance(handler,
+        # logging.StreamHandler) is True even if handler is FileHandler.
+        # if (type(handler) == logging.StreamHandler) and (handler.stream == sys.stderr):
+        elif type(handler) == logging.StreamHandler:
+            logger.removeHandler(handler)
+            
+    file_handler = logging.FileHandler(filename)
+    file_handler.setFormatter(logging.Formatter('%(message)s'))
+    logger.addHandler(file_handler)
+
+    console_handler = logging.StreamHandler()
+    console_handler.setFormatter(logging.Formatter('%(message)s'))
+    logger.addHandler(console_handler)
+    return logger
+
+    

+ 1 - 1
khandy/version.py

@@ -1,3 +1,3 @@
-__version__ = '0.1.3'
+__version__ = '0.1.4'
 
 __all__ = ['__version__']

+ 1 - 1
setup.py

@@ -5,7 +5,7 @@ install_requires = ['numpy>=1.11.1', 'opencv-python', 'pillow']
 
 setup(
     name='KHandy',
-    version='0.1.3',
+    version='0.1.4',
     description='Handy Utilities for Computer Vision',
     long_description='Handy Utilities for Computer Vision',
     keywords='computer vision',