def testLogLevel(self): from girder import logger, _attachFileLogHandlers _attachFileLogHandlers() for handler in logger.handlers: if handler._girderLogHandler == 'info': handler.emit = unittest.mock.MagicMock() infoEmit = handler.emit elif handler._girderLogHandler == 'error': handler.emit = unittest.mock.MagicMock() errorEmit = handler.emit # We should be an info level resp = self.request(path='/system/log/level', user=self.users[0]) self.assertStatusOk(resp) self.assertEqual(resp.json, 'DEBUG') levels = [{ 'level': 'INFO', 'debug': (0, 0), 'info': (1, 0), 'error': (0, 1), }, { 'level': 'ERROR', 'debug': (0, 0), 'info': (0, 0), 'error': (0, 1), }, { 'level': 'CRITICAL', 'debug': (0, 0), 'info': (0, 0), 'error': (0, 0), }, { 'level': 'DEBUG', 'debug': (1, 0), 'info': (1, 0), 'error': (0, 1), }] for levelTest in levels: resp = self.request(method='PUT', path='/system/log/level', user=self.users[0], params={'level': levelTest['level']}) self.assertStatusOk(resp) self.assertEqual(resp.json, levelTest['level']) resp = self.request(path='/system/log/level', user=self.users[0]) self.assertStatusOk(resp) self.assertEqual(resp.json, levelTest['level']) for level in ('debug', 'info', 'error'): infoCount, errorCount = infoEmit.call_count, errorEmit.call_count getattr(logger, level)('log entry %s %s' % (levelTest['level'], level)) self.assertEqual(infoEmit.call_count, infoCount + levelTest[level][0]) self.assertEqual(errorEmit.call_count, errorCount + levelTest[level][1]) # Try to set a bad log level resp = self.request(method='PUT', path='/system/log/level', user=self.users[0], params={'level': 'NOSUCHLEVEL'}) self.assertStatus(resp, 400) self.assertIn('Invalid value for level', resp.json['message'])
def mountServer(path, database=None, fuseOptions=None, quiet=False, plugins=None): """ Perform the mount. :param path: the mount location. :param database: a database connection URI, if it contains '://'. Otherwise, the default database is used. :param fuseOptions: a comma-separated string of options to pass to the FUSE mount. A key without a value is taken as True. Boolean values are case insensitive. For instance, 'foreground' or 'foreground=True' will keep this program running until the SIGTERM or unmounted. :param quiet: if True, suppress Girder logs. :param plugins: an optional list of plugins to enable. If None, use the plugins that are configured. """ if quiet: curConfig = config.getConfig() curConfig.setdefault('logging', {})['log_quiet'] = True curConfig.setdefault('logging', {})['log_level'] = 'FATAL' girder._attachFileLogHandlers() if database and '://' in database: cherrypy.config['database']['uri'] = database if plugins is not None: plugins = plugins.split(',') webroot, appconf = configureServer(plugins=plugins) girder._setupCache() opClass = ServerFuse(stat=os.stat(path)) options = { # By default, we run in the background so the mount command returns # immediately. If we run in the foreground, a SIGTERM will shut it # down 'foreground': False, # Cache files if their size and timestamp haven't changed. # This lets the OS buffer files efficiently. 'auto_cache': True, # We aren't specifying our own inos 'use_ino': False, # read-only file system 'ro': True, } if sys.platform != 'darwin': # Automatically unmount when we try to mount again options['auto_unmount'] = True if fuseOptions: for opt in fuseOptions.split(','): if '=' in opt: key, value = opt.split('=', 1) value = (False if value.lower() == 'false' else True if value.lower() == 'true' else value) else: key, value = opt, True if key in ('use_ino', 'ro', 'rw') and options.get(key) != value: logprint.warning('Ignoring the %s=%r option' % (key, value)) continue options[key] = value Setting().set(SettingKey.GIRDER_MOUNT_INFORMATION, {'path': path, 'mounttime': time.time()}) FUSELogError(opClass, path, **options)
def testLogLevel(self): from girder import logger, _attachFileLogHandlers _attachFileLogHandlers() for handler in logger.handlers: if getattr(handler, '_girderLogHandler') == 'info': handler.emit = mock.MagicMock() infoEmit = handler.emit elif getattr(handler, '_girderLogHandler') == 'error': handler.emit = mock.MagicMock() errorEmit = handler.emit # We should be an info level resp = self.request(path='/system/log/level', user=self.users[0]) self.assertStatusOk(resp) self.assertEqual(resp.json, 'DEBUG') levels = [{ 'level': 'INFO', 'debug': (0, 0), 'info': (1, 0), 'error': (0, 1), }, { 'level': 'ERROR', 'debug': (0, 0), 'info': (0, 0), 'error': (0, 1), }, { 'level': 'CRITICAL', 'debug': (0, 0), 'info': (0, 0), 'error': (0, 0), }, { 'level': 'DEBUG', 'debug': (1, 0), 'info': (1, 0), 'error': (0, 1), }] for levelTest in levels: resp = self.request( method='PUT', path='/system/log/level', user=self.users[0], params={'level': levelTest['level']}) self.assertStatusOk(resp) self.assertEqual(resp.json, levelTest['level']) resp = self.request(path='/system/log/level', user=self.users[0]) self.assertStatusOk(resp) self.assertEqual(resp.json, levelTest['level']) for level in ('debug', 'info', 'error'): infoCount, errorCount = infoEmit.call_count, errorEmit.call_count getattr(logger, level)('log entry %s %s' % ( levelTest['level'], level)) self.assertEqual(infoEmit.call_count, infoCount + levelTest[level][0]) self.assertEqual(errorEmit.call_count, errorCount + levelTest[level][1]) # Try to set a bad log level resp = self.request( method='PUT', path='/system/log/level', user=self.users[0], params={'level': 'NOSUCHLEVEL'}) self.assertStatus(resp, 400) self.assertIn('Invalid value for level', resp.json['message'])
def main(testing, database, host, port): if database: cherrypy.config['database']['uri'] = database if host: cherrypy.config['server.socket_host'] = host if port: cherrypy.config['server.socket_port'] = port _attachFileLogHandlers() server.setup(testing) cherrypy.engine.start() cherrypy.engine.block()
def configureLogging(logConfig={}, oneFile=False): cfg = config.getConfig() if oneFile: cfg['logging']['error_log_file'] = cfg['logging']['info_log_file'] else: cfg['logging']['error_log_file'] = cfg['logging']['original_error_log_file'] if os.path.exists(cfg['logging']['info_log_file']): os.unlink(cfg['logging']['info_log_file']) if os.path.exists(cfg['logging']['error_log_file']): os.unlink(cfg['logging']['error_log_file']) cfg['logging'].update(logConfig) girder._attachFileLogHandlers() return cfg['logging']
def configureLogging(logConfig=None, oneFile=False): cfg = config.getConfig() if oneFile: cfg['logging']['error_log_file'] = cfg['logging']['info_log_file'] else: cfg['logging']['error_log_file'] = cfg['logging']['original_error_log_file'] if os.path.exists(cfg['logging']['info_log_file']): os.unlink(cfg['logging']['info_log_file']) if os.path.exists(cfg['logging']['error_log_file']): os.unlink(cfg['logging']['error_log_file']) cfg['logging'].update(logConfig or {}) girder._attachFileLogHandlers() return cfg['logging']
def main(testing, database, host, port): # If the user provides no options, the existing config values get re-set through click cherrypy.config['database']['uri'] = database if six.PY2: # On Python 2, click returns the value as unicode and CherryPy expects a str # Keep this conversion explicitly for Python 2 only, so it can be removed when Python 2 # support is dropped host = str(host) cherrypy.config['server.socket_host'] = host cherrypy.config['server.socket_port'] = port _attachFileLogHandlers() server.setup(testing) cherrypy.engine.start() cherrypy.engine.block()
def main(dev, mode, database, host, port): if dev and mode: raise click.ClickException('Conflict between --dev and --mode') if dev: mode = ServerMode.DEVELOPMENT # If the user provides no options, the existing config values get re-set through click cherrypy.config['database']['uri'] = database cherrypy.config['server.socket_host'] = host cherrypy.config['server.socket_port'] = port _attachFileLogHandlers() server.setup(mode) cherrypy.engine.start() cherrypy.engine.block()