本文整理汇总了Python中mozlog.commandline.setup_logging函数的典型用法代码示例。如果您正苦于以下问题:Python setup_logging函数的具体用法?Python setup_logging怎么用?Python setup_logging使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setup_logging函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _lint
def _lint(self, files, linter, **lintargs):
payload = linter["payload"]
handler = LintHandler(linter)
logger = linter.get("logger")
if logger is None:
logger = get_default_logger()
if logger is None:
logger = structuredlog.StructuredLogger(linter["name"])
commandline.setup_logging(logger, {}, {"mach": sys.stdout})
logger.add_handler(handler)
try:
payload(files, logger, **lintargs)
except KeyboardInterrupt:
pass
return handler.results
示例2: test_setup_logging_optparse
def test_setup_logging_optparse(self):
parser = optparse.OptionParser()
commandline.add_logging_group(parser)
args, _ = parser.parse_args(["--log-raw=-"])
logger = commandline.setup_logging("test_optparse", args, {})
self.assertEqual(len(logger.handlers), 1)
self.assertIsInstance(logger.handlers[0], handlers.StreamHandler)
示例3: run_mochitest
def run_mochitest(context, **kwargs):
from mochitest_options import ALL_FLAVORS
from mozlog.commandline import setup_logging
if not kwargs.get('log'):
kwargs['log'] = setup_logging('mochitest', kwargs, {'mach': sys.stdout})
flavor = kwargs.get('flavor') or 'mochitest'
if flavor not in ALL_FLAVORS:
for fname, fobj in ALL_FLAVORS.iteritems():
if flavor in fobj['aliases']:
flavor = fname
break
fobj = ALL_FLAVORS[flavor]
kwargs.update(fobj.get('extra_args', {}))
args = Namespace(**kwargs)
args.e10s = context.mozharness_config.get('e10s', args.e10s)
args.certPath = context.certs_dir
if args.test_paths:
install_subdir = fobj.get('install_subdir', fobj['suite'])
test_root = os.path.join(context.package_root, 'mochitest', install_subdir)
normalize = partial(context.normalize_test_path, test_root)
args.test_paths = map(normalize, args.test_paths)
import mozinfo
if mozinfo.info.get('buildapp') == 'mobile/android':
return run_mochitest_android(context, args)
return run_mochitest_desktop(context, args)
示例4: main
def main():
parser = parser_b2g()
options = parser.parse_args()
log = commandline.setup_logging("Remote XPCShell",
options,
{"tbpl": sys.stdout})
run_remote_xpcshell(parser, options, log)
示例5: run_cppunit_test
def run_cppunit_test(self, **params):
import mozinfo
from mozlog import commandline
import runcppunittests as cppunittests
log = commandline.setup_logging("cppunittest",
{},
{"tbpl": sys.stdout})
if len(params['test_files']) == 0:
testdir = os.path.join(self.distdir, 'cppunittests')
manifest = os.path.join(self.topsrcdir, 'testing', 'cppunittest.ini')
tests = cppunittests.extract_unittests_from_args([testdir], mozinfo.info, manifest)
else:
tests = cppunittests.extract_unittests_from_args(params['test_files'], mozinfo.info, None)
# See if we have crash symbols
symbols_path = os.path.join(self.distdir, 'crashreporter-symbols')
if not os.path.isdir(symbols_path):
symbols_path = None
tester = cppunittests.CPPUnitTests()
try:
result = tester.run_tests(tests, self.bindir, symbols_path, interactive=True)
except Exception as e:
log.error("Caught exception running cpp unit tests: %s" % str(e))
result = False
return 0 if result else 1
示例6: _lint
def _lint(self, files, config, **lintargs):
handler = LintHandler(config)
logger = config.get("logger")
if logger is None:
logger = get_default_logger()
if logger is None:
logger = structuredlog.StructuredLogger(config["name"])
commandline.setup_logging(logger, {}, {"mach": sys.stdout})
logger.add_handler(handler)
func = findobject(config["payload"])
try:
func(files, config, logger, **lintargs)
except KeyboardInterrupt:
pass
return handler.results
示例7: main
def main():
parser = B2GOptions()
commandline.add_logging_group(parser)
options, args = parser.parse_args()
log = commandline.setup_logging("Remote XPCShell",
options,
{"tbpl": sys.stdout})
run_remote_xpcshell(parser, options, args, log)
示例8: setup
def setup(args, defaults):
logger = commandline.setup_logging("web-platform-tests", args, defaults)
setup_stdlib_logger()
for name in args.keys():
if name.startswith("log_"):
args.pop(name)
return logger
示例9: main
def main():
if sys.version_info < (2,7):
print >>sys.stderr, "Error: You must use python version 2.7 or newer but less than 3.0"
sys.exit(1)
parser = RemoteXPCShellOptions()
commandline.add_logging_group(parser)
options, args = parser.parse_args()
if not options.localAPK:
for file in os.listdir(os.path.join(options.objdir, "dist")):
if (file.endswith(".apk") and file.startswith("fennec")):
options.localAPK = os.path.join(options.objdir, "dist")
options.localAPK = os.path.join(options.localAPK, file)
print >>sys.stderr, "using APK: " + options.localAPK
break
else:
print >>sys.stderr, "Error: please specify an APK"
sys.exit(1)
options = parser.verifyRemoteOptions(options)
log = commandline.setup_logging("Remote XPCShell",
options,
{"tbpl": sys.stdout})
if len(args) < 1 and options.manifest is None:
print >>sys.stderr, """Usage: %s <test dirs>
or: %s --manifest=test.manifest """ % (sys.argv[0], sys.argv[0])
sys.exit(1)
if options.dm_trans == "adb":
if options.deviceIP:
dm = mozdevice.DroidADB(options.deviceIP, options.devicePort, packageName=None, deviceRoot=options.remoteTestRoot)
else:
dm = mozdevice.DroidADB(packageName=None, deviceRoot=options.remoteTestRoot)
else:
if not options.deviceIP:
print "Error: you must provide a device IP to connect to via the --device option"
sys.exit(1)
dm = mozdevice.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot)
if options.interactive and not options.testPath:
print >>sys.stderr, "Error: You must specify a test filename in interactive mode!"
sys.exit(1)
xpcsh = XPCShellRemote(dm, options, args, log)
# we don't run concurrent tests on mobile
options.sequential = True
if not xpcsh.runTests(xpcshell='xpcshell',
testClass=RemoteXPCShellTestThread,
testdirs=args[0:],
mobileArgs=xpcsh.mobileArgs,
**options.__dict__):
sys.exit(1)
示例10: setup_logging
def setup_logging(args, defaults):
global logger
logger = commandline.setup_logging("web-platform-tests-unstable", args, defaults)
wptrunner.setup_stdlib_logger()
for name in args.keys():
if name.startswith("log_"):
args.pop(name)
return logger
示例11: test_logging_errorlevel
def test_logging_errorlevel(self):
parser = argparse.ArgumentParser()
commandline.add_logging_group(parser)
args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=error"])
logger = commandline.setup_logging("test_fmtopts", args, {})
logger.info("INFO message")
logger.debug("DEBUG message")
logger.error("ERROR message")
# Only the error level and above were requested.
self.assertEqual(["ERROR message"],
self.loglines)
示例12: main
def main():
parser = get_parser()
commandline.add_logging_group(parser)
args = parser.parse_args()
logger = commandline.setup_logging("structured-example", args, {"raw": sys.stdout})
runner = TestRunner()
try:
runner.run()
except Exception:
logger.critical("Error during test run:\n%s" % traceback.format_exc())
示例13: test_logging_debuglevel
def test_logging_debuglevel(self):
parser = argparse.ArgumentParser()
commandline.add_logging_group(parser)
args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=debug"])
logger = commandline.setup_logging("test_fmtopts", args, {})
logger.info("INFO message")
logger.debug("DEBUG message")
logger.error("ERROR message")
# Requesting a lower log level than default works as expected.
self.assertEqual(["INFO message",
"DEBUG message",
"ERROR message"],
self.loglines)
示例14: test_logging_defaultlevel
def test_logging_defaultlevel(self):
parser = argparse.ArgumentParser()
commandline.add_logging_group(parser)
args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name])
logger = commandline.setup_logging("test_fmtopts", args, {})
logger.info("INFO message")
logger.debug("DEBUG message")
logger.error("ERROR message")
# The debug level is not logged by default.
self.assertEqual(["INFO message",
"ERROR message"],
self.loglines)
示例15: setup
def setup(args, defaults):
logger = args.pop('log', None)
if logger:
set_default_logger(logger)
StructuredLogger._logger_states["web-platform-tests"] = logger._state
else:
logger = commandline.setup_logging("web-platform-tests", args, defaults)
setup_stdlib_logger()
for name in args.keys():
if name.startswith("log_"):
args.pop(name)
return logger