def run_debug(script, timeout): import logging config = calvinconfig.get() debug_modules = config.get('developer', 'debug_modules') if not debug_modules: print "No 'debug_modules' option in 'developer' section of config => output verbosity is DEBUG everywhere." calvinlogger.get_logger().setLevel(logging.DEBUG) else: for m in debug_modules: calvinlogger.get_logger(m).setLevel(logging.DEBUG) print "\n{0}\n{1}\n{0}".format("-"*80, config) run(script, timeout)
def test_get_logger(logging_mock): calvinlogger._log = None log_mock = Mock() logging_mock.getLogger = Mock(return_value=log_mock) log = calvinlogger.get_logger() assert logging_mock.getLogger.called log_mock.setLevel.assert_called_with(logging_mock.INFO) assert log == log_mock log = calvinlogger.get_logger(name="abc") assert log == log_mock.getChild("abc")
def test_analyze(extract_stack, node_id, func, param, peer_node_id, tb, mute, args, kwargs): calvinlogger._log = None log = calvinlogger.get_logger() log.isEnabledFor = Mock(return_value=True) log._log = Mock() log.analyze(node_id=node_id, func=func, param=param, peer_node_id=peer_node_id, tb=tb, mute=mute, args=args, kwargs=kwargs) if mute: assert not log._log.called else: expected_stack = None if tb: expected_stack = "stack" correct_msg = { "peer_node_id": peer_node_id, "node_id": node_id, "func": func, "param": param, "stack": expected_stack } # JSON might reorder the dict hence need detailed assert assert log._log.call_args[0][0] == 5 assert log._log.call_args[0][1].startswith("[[ANALYZE]]") test_msg = json.loads(log._log.call_args[0][1][11:]) assert correct_msg == test_msg assert log._log.call_args[0][2] == () assert log._log.call_args[1]['args'] == args assert log._log.call_args[1]['kwargs'] == kwargs if tb: assert extract_stack.called else: assert not extract_stack.called
def pytest_configure(config): levels = config.getoption("loglevel") for level in levels: module = None if ":" in level: module, level = level.split(":") print("Setting debuglevel %s on module %s" % (level, module)) if level == "CRITICAL": calvinlogger.get_logger(module).setLevel(logging.CRITICAL) elif level == "ERROR": calvinlogger.get_logger(module).setLevel(logging.ERROR) elif level == "WARNING": calvinlogger.get_logger(module).setLevel(logging.WARNING) elif level == "INFO": calvinlogger.get_logger(module).setLevel(logging.INFO) elif level == "DEBUG": calvinlogger.get_logger(module).setLevel(logging.DEBUG)
def deploy(rt, app_info, loglevel): d = {} try: d = deployer.Deployer(rt, app_info) d.deploy() except Exception: time.sleep(0.1) if get_logger().getEffectiveLevel <= logging.DEBUG: traceback.print_exc() return d.app_id
def deploy(rt, app_info): from calvin.Tools import deployer d = {} try: d = deployer.Deployer(rt, app_info) d.deploy() except: from calvin.utilities.calvinlogger import get_logger time.sleep(0.1) if get_logger().getEffectiveLevel <= logging.DEBUG: traceback.print_exc() return d.app_id
def set_loglevel(verbose, quiet): logger = get_logger() if quiet: logger.setLevel(logging.WARNING) else: logger.setLevel(logging.INFO) if verbose == 1: dtrace._trace_on = True logger.setLevel(logging.INFO) elif verbose == 2: dtrace._trace_on = True logger.setLevel(logging.DEBUG) else: dtrace._trace_on = False logger.setLevel(logging.INFO)
def set_loglevel(levels, filename): from calvin.utilities.calvinlogger import get_logger, set_file global _log if filename: set_file(filename) _log = get_logger(__name__) if not levels: get_logger().setLevel(logging.INFO) return for level in levels: module = None if ":" in level: module, level = level.split(":") if level == "CRITICAL": get_logger(module).setLevel(logging.CRITICAL) elif level == "ERROR": get_logger(module).setLevel(logging.ERROR) elif level == "WARNING": get_logger(module).setLevel(logging.WARNING) elif level == "INFO": get_logger(module).setLevel(logging.INFO) elif level == "DEBUG": get_logger(module).setLevel(logging.DEBUG) elif level == "ANALYZE": get_logger(module).setLevel(5)
from calvin.utilities import calvinuuid from calvin.utilities.issuetracker import IssueTracker # # Dynamically build selected set of APIs # from control_apis import routes from control_apis import security_api from control_apis import runtime_api from control_apis import application_api from control_apis import documentation_api from control_apis import logging_api from control_apis import metering_api from control_apis import registry_api from control_apis import uicalvinsys_api _log = get_logger(__name__) _calvincontrol = None def get_calvincontrol(): """ Returns the CalvinControl singleton """ global _calvincontrol if _calvincontrol is None: _calvincontrol = CalvinControl() return _calvincontrol class CalvinControl(object): """ A HTTP REST API for calvin nodes
def pytest_configure(config): global _config_pytest _config_pytest = config filename = config.getoption("logfile") if filename: calvinlogger.set_file(filename) levels = config.getoption("loglevel") for level in levels: module = None if ":" in level: module, level = level.split(":") print("Setting debuglevel %s on module %s" % (level, module)) if level == "CRITICAL": calvinlogger.get_logger(module).setLevel(logging.CRITICAL) elif level == "ERROR": calvinlogger.get_logger(module).setLevel(logging.ERROR) elif level == "WARNING": calvinlogger.get_logger(module).setLevel(logging.WARNING) elif level == "INFO": calvinlogger.get_logger(module).setLevel(logging.INFO) elif level == "DEBUG": calvinlogger.get_logger(module).setLevel(logging.DEBUG) elif level == "ANALYZE": calvinlogger.get_logger(module).setLevel(5) if not os.environ.get('CALVIN_GLOBAL_DHT_NETWORK_FILTER'): # TODO: add func to set any argument from here also from calvin.utilities import calvinconfig _conf = calvinconfig.get() _conf.add_section('ARGUMENTS') _conf.set('ARGUMENTS', 'DHT_NETWORK_FILTER', str(uuid.uuid4()))
def setup_logging(filename): #from twisted.python import log #from twisted.internet import defer #import sys #defer.setDebugging(True) #log.startLogging(sys.stdout) levels = os.getenv('CALVIN_TESTS_LOG_LEVELS', "").split(':') set_file(filename) if not levels: get_logger().setLevel(logging.INFO) return for level in levels: module = None if ":" in level: module, level = level.split(":") if level == "CRITICAL": get_logger(module).setLevel(logging.CRITICAL) elif level == "ERROR": get_logger(module).setLevel(logging.ERROR) elif level == "WARNING": get_logger(module).setLevel(logging.WARNING) elif level == "INFO": get_logger(module).setLevel(logging.INFO) elif level == "DEBUG": get_logger(module).setLevel(logging.DEBUG) elif level == "ANALYZE": get_logger(module).setLevel(5)
def pytest_configure(config): filename = config.getoption("logfile") if filename: calvinlogger.set_file(filename) levels = config.getoption("loglevel") for level in levels: module = None if ":" in level: module, level = level.split(":") print("Setting debuglevel %s on module %s" % (level, module)) if level == "CRITICAL": calvinlogger.get_logger(module).setLevel(logging.CRITICAL) elif level == "ERROR": calvinlogger.get_logger(module).setLevel(logging.ERROR) elif level == "WARNING": calvinlogger.get_logger(module).setLevel(logging.WARNING) elif level == "INFO": calvinlogger.get_logger(module).setLevel(logging.INFO) elif level == "DEBUG": calvinlogger.get_logger(module).setLevel(logging.DEBUG) elif level == "ANALYZE": calvinlogger.get_logger(module).setLevel(5) # TODO: add func to set any argument from here also from calvin.utilities import calvinconfig _conf = calvinconfig.get() _conf.add_section('ARGUMENTS') _conf.set('ARGUMENTS', 'DHT_NETWORK_FILTER', str(uuid.uuid4()))
def set_loglevel(levels): if not levels: get_logger().setLevel(logging.INFO) return for level in levels: module = None if ":" in level: module, level = level.split(":") if level == "CRITICAL": get_logger(module).setLevel(logging.CRITICAL) elif level == "ERROR": get_logger(module).setLevel(logging.ERROR) elif level == "WARNING": get_logger(module).setLevel(logging.WARNING) elif level == "INFO": get_logger(module).setLevel(logging.INFO) elif level == "DEBUG": get_logger(module).setLevel(logging.DEBUG)
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from calvin.utilities import calvinlogger from twisted.twisted_transport import TwistedCalvinServer, TwistedCalvinTransport from calvin.runtime.south.transports import base_transport from calvin.runtime.south.transports.lib.twisted import twisted_transport _log = calvinlogger.get_logger(__name__) class CalvinTransportFactory(base_transport.BaseTransportFactory): def __init__(self, rt_id, callbacks): super(CalvinTransportFactory, self).__init__(rt_id, callbacks=callbacks) self._peers = {} self._servers = {} self._callbacks = callbacks def _peer_connected(self): pass def join(self, uri): """docstring for join"""
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import glob import importlib from calvin.utilities import calvinuuid from calvin.utilities.calvin_callback import CalvinCB import calvin.utilities.calvinresponse as response from calvin.runtime.south.plugins. async import async from calvin.utilities import calvinlogger _log = calvinlogger.get_logger(__name__) # FIXME should be read from calvin config TRANSPORT_PLUGIN_PATH = os.path.join( os.path.dirname(os.path.dirname(__file__)), *['south', 'plugins', 'transports']) TRANSPORT_PLUGIN_NS = "calvin.runtime.south.plugins.transports" class CalvinLink(object): """ CalvinLink class manage one RT to RT link between rt_id and peer_id using transport as mechanism. transport: a plug-in transport object old_link: should be supplied when we replace an existing link, will be closed """ def __init__(self, rt_id, peer_id, transport, old_link=None):
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from calvin.actor.actor import Actor, ActionResult, manage, condition from calvin.utilities.calvinlogger import get_logger _log = get_logger(__name__) class StandardOut(Actor): """ Write tokens to standard output Input: token : Any token """ def exception_handler(self, action, args, context): # Check args to verify that it is EOSToken return action(self, *args) @manage(['tokens', 'store_tokens', 'quiet', '_replicate']) def init(self, store_tokens=False, quiet=False, replicate=False):