* Simplified logging helper.

* Fixed think-o in how to close the CollectionWrapper inside a ThreadingCollectionWrapper.
This commit is contained in:
David Snopek 2013-07-18 02:17:36 +01:00
parent f891a939c3
commit 9207f3bce4
3 changed files with 30 additions and 16 deletions

View File

@ -478,9 +478,7 @@ class CardHandler(RestHandlerBase):
def make_app(global_conf, **local_conf):
# setup the logger
from AnkiServer.utils import setup_logging
logging_config_file = local_conf.get('logging.config_file')
if logging_config_file:
setup_logging(logging_config_file)
setup_logging(local_conf.get('logging.config_file'))
return RestApp(
data_root=local_conf.get('data_root', '.'),

View File

@ -114,11 +114,21 @@ class ThreadingCollectionWrapper(object):
if self._thread is not None:
self._thread.join()
#
# Mimic the CollectionWrapper interface
#
def open(self):
"""Non-op. The collection will be opened on demand."""
pass
def close(self):
self.stop()
"""Closes the underlying collection without stopping the thread."""
def _close(col):
self.wrapper.close()
self.execute(_close, waitForReturn=False)
def opened(self):
return self.wrapper.opened()
@ -152,15 +162,18 @@ class ThreadingCollectionManager(CollectionManager):
for path, thread in self.collections.items():
if thread.running and thread.wrapper.opened() and thread.qempty() and cur - thread.last_timestamp >= self.monitor_inactivity:
logging.info('Monitor is closing collection on inactive CollectionThread[%s]', thread.path)
def closeCollection(wrapper):
wrapper.close()
thread.execute(closeCollection, waitForReturn=False)
thread.close()
time.sleep(self.monitor_frequency)
def shutdown(self):
# TODO: stop the monitor thread!
# This will stop all the collection threads
# stop all the threads
for path, col in self.collections.items():
del self.collections[path]
col.stop()
# let the parent do whatever else it might want to do...
super(ThreadingCollectionManager, self).shutdown()
#

View File

@ -1,15 +1,18 @@
def setup_logging(config_file):
def setup_logging(config_file=None):
"""Setup logging based on a config_file."""
import logging
# monkey patch the logging.config.SMTPHandler if necessary
import sys
if sys.version_info[0] == 2 and sys.version_info[1] == 5:
import AnkiServer.logpatch
if config_file is not None:
# monkey patch the logging.config.SMTPHandler if necessary
import sys
if sys.version_info[0] == 2 and sys.version_info[1] == 5:
import AnkiServer.logpatch
# load the config file
import logging.config
logging.config.fileConfig(config_file)
# load the config file
import logging.config
logging.config.fileConfig(config_file)
else:
logging.getLogger().setLevel(logging.INFO)