本文整理汇总了Python中mozlog.getLogger函数的典型用法代码示例。如果您正苦于以下问题:Python getLogger函数的具体用法?Python getLogger怎么用?Python getLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getLogger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(args=sys.argv[1:]):
"""
Return codes
0 - success
1 - test failures
2 - fatal error
"""
parser = PeptestOptions()
options, args = parser.parse_args()
options = parser.verifyOptions(options)
if options == None:
return 2
# setup the logging
if options.logFile:
handler = mozlog.FileHandler(options.logFile)
handler.setFormatter(mozlog.MozFormatter())
logger = mozlog.getLogger('PEP', handler)
else:
logger = mozlog.getLogger('PEP')
if options.logLevel:
logger.setLevel(getattr(mozlog, options.logLevel, 'INFO'))
try:
peptest = applications[options.app](options)
return peptest.start()
except Exception:
cla, exc = sys.exc_info()[:2]
logger.error("%s: %s" % (cla.__name__, exc))
logger.debug("Traceback:\n%s" % (traceback.format_exc()))
return 2
示例2: test_logger_defaults
def test_logger_defaults(self):
"""Tests the default logging format and behavior."""
default_logger = mozlog.getLogger("default.logger")
self.assertEqual(default_logger.name, "default.logger")
self.assertEqual(len(default_logger.handlers), 1)
self.assertTrue(isinstance(default_logger.handlers[0], mozlog.StreamHandler))
f = mozfile.NamedTemporaryFile()
list_logger = mozlog.getLogger("file.logger", handler=mozlog.FileHandler(f.name))
self.assertEqual(len(list_logger.handlers), 1)
self.assertTrue(isinstance(list_logger.handlers[0], mozlog.FileHandler))
f.close()
self.assertRaises(ValueError, mozlog.getLogger, "file.logger", handler=ListHandler())
示例3: cli
def cli():
parser = OptionParser(usage='%prog [options] <test_file> <test_file> ...')
parser.add_option("--binary",
action="store", dest="binary",
default=None,
help="path to B2G desktop build binary")
parser.add_option("--profile",
action="store", dest="profile",
default=None,
help="path to gaia profile directory")
options, tests = parser.parse_args()
if not options.binary or not options.profile:
parser.print_usage()
parser.exit('--binary and --profile required')
if not tests:
# Read in a list of tests to skip from disabled.json, if it exists;
# disabled.json should contain filenames with paths relative to the
# apps directory, e.g., "wallpaper/test/unit/pick_test.js".
disabled = []
disabled_file = os.path.join(os.path.dirname(__file__), 'disabled.json')
if os.access(disabled_file, os.F_OK):
with open(disabled_file, 'r') as f:
disabled_contents = f.read()
try:
disabled = json.loads(disabled_contents)
except:
traceback.print_exc()
print "Error while decoding disabled.json; please make sure this file has valid JSON syntax."
sys.exit(1)
# build a list of tests
appsdir = os.path.join(os.path.dirname(os.path.abspath(options.profile)), 'apps')
for root, dirs, files in os.walk(appsdir):
for file in files:
full_path = os.path.relpath(os.path.join(root, file), appsdir)
if full_path[-8:] == '_test.js' and full_path not in disabled:
tests.append(full_path)
runner = GaiaUnitTestRunner(binary=options.binary,
profile=options.profile)
runner.run()
# Lame but necessary hack to prevent tornado's logger from duplicating
# every message from mozlog.
logger = logging.getLogger()
handler = logging.NullHandler()
logger.addHandler(handler)
print 'starting WebSocket Server'
application = tornado.web.Application([
(r"/", TestAgentServer, {'tests': tests,
'runner': runner,
'logger': mozlog.getLogger('gaia-unit-tests')}),
])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8789)
tornado.ioloop.IOLoop.instance().start()
示例4: __init__
def __init__(self, device_serial=None):
self.device_serial = device_serial
self._logger = structured.get_default_logger(component='b2gmonkey')
if not self._logger:
self._logger = mozlog.getLogger('b2gmonkey')
self.version = mozversion.get_version(
dm_type='adb', device_serial=device_serial)
device_id = self.version.get('device_id')
if not device_id:
raise B2GMonkeyError('Firefox OS device not found.')
self.device_properties = DEVICE_PROPERTIES.get(device_id)
if not self.device_properties:
raise B2GMonkeyError('Unsupported device: \'%s\'' % device_id)
android_version = self.version.get('device_firmware_version_release')
if device_id == 'flame' and android_version == '4.4.2':
self.device_properties.update(DEVICE_PROPERTIES.get('flame-kk'))
self.temp_dir = tempfile.mkdtemp()
if 'MINIDUMP_SAVE_PATH' not in os.environ:
self.crash_dumps_path = os.path.join(self.temp_dir, 'crashes')
os.environ['MINIDUMP_SAVE_PATH'] = self.crash_dumps_path
else:
self.crash_dumps_path = os.environ['MINIDUMP_SAVE_PATH']
示例5: gather_debug
def gather_debug(test, status):
rv = {}
marionette = test._marionette_weakref()
# In the event we're gathering debug without starting a session, skip marionette commands
if marionette.session is not None:
try:
marionette.switch_to_frame()
rv["settings"] = json.dumps(
marionette.execute_async_script(
"""
SpecialPowers.pushPermissions([
{type: 'settings-read', allow: true, context: document},
{type: 'settings-api-read', allow: true, context: document},
], function() {
var req = window.navigator.mozSettings.createLock().get('*');
req.onsuccess = function() {
marionetteScriptFinished(req.result);
}
});""",
special_powers=True,
),
sort_keys=True,
indent=4,
separators=(",", ": "),
)
except:
logger = mozlog.structured.get_default_logger()
if not logger:
logger = mozlog.getLogger("gaiatest")
logger.warning("Failed to gather test failure debug.", exc_info=True)
return rv
示例6: __init__
def __init__(self, tests, testfile=None,
es_server=None, rest_server=None, testgroup='marionette'):
self.logger = mozlog.getLogger('B2G_AUTOMATION')
self.tests = tests
self.testfile = testfile
self.es_server = es_server
self.rest_server = rest_server
self.testgroup = testgroup
self.lock = RLock()
self.logger.info("Testlist: %s" % self.tests)
pulse = B2GPulseConsumer(applabel='b2g_build_listener')
pulse.configure(topic='#', callback=self.on_build)
if not self.testfile:
self.logger.info('waiting for pulse messages...')
pulse.listen()
else:
t = Thread(target=pulse.listen)
t.daemon = True
t.start()
f = open(self.testfile, 'r')
data = json.loads(f.read())
self.on_build(data, None)
示例7: __init__
def __init__(self, **kwargs):
# Set up the log file or use stdout if none specified
self.log = mozlog.getLogger('FB_UPDATE', kwargs.get('log'))
self.log.setLevel(mozlog.DEBUG if kwargs.get('debug') else mozlog.INFO)
self.repo = kwargs.get('repo')
self.serverpath = kwargs.get('serverpath')
示例8: __init__
def __init__(self, marionette, datazilla_config=None, sources=None,
log_level='INFO'):
# Set up logging
handler = mozlog.StreamHandler()
handler.setFormatter(mozlog.MozFormatter(include_timestamp=True))
self.logger = mozlog.getLogger(self.__class__.__name__, handler)
self.logger.setLevel(getattr(mozlog, log_level.upper()))
self.marionette = marionette
settings = gaiatest.GaiaData(self.marionette).all_settings
mac_address = self.marionette.execute_script(
'return navigator.mozWifiManager && '
'navigator.mozWifiManager.macAddress;')
self.submit_report = True
self.ancillary_data = {}
self.ancillary_data['generated_by'] = 'b2gperf %s' % __version__
self.device = gaiatest.GaiaDevice(self.marionette)
dm = mozdevice.DeviceManagerADB()
self.device.add_device_manager(dm)
version = mozversion.get_version(sources=sources, dm_type='adb')
self.ancillary_data['build_revision'] = version.get('build_changeset')
self.ancillary_data['gaia_revision'] = version.get('gaia_changeset')
self.ancillary_data['gecko_revision'] = version.get('gecko_changeset')
self.ancillary_data['ro.build.version.incremental'] = version.get(
'device_firmware_version_incremental')
self.ancillary_data['ro.build.version.release'] = version.get(
'device_firmware_version_release')
self.ancillary_data['ro.build.date.utc'] = version.get(
'device_firmware_date')
self.required = {
'generated by': self.ancillary_data.get('generated_by'),
'gaia revision': self.ancillary_data.get('gaia_revision'),
'gecko revision': self.ancillary_data.get('gecko_revision'),
'build revision': self.ancillary_data.get('build_revision'),
'protocol': datazilla_config['protocol'],
'host': datazilla_config['host'],
'project': datazilla_config['project'],
'branch': datazilla_config['branch'],
'oauth key': datazilla_config['oauth_key'],
'oauth secret': datazilla_config['oauth_secret'],
'machine name': datazilla_config['machine_name'] or mac_address,
'device name': datazilla_config['device_name'],
'os version': settings.get('deviceinfo.os'),
'id': settings.get('deviceinfo.platform_build_id')}
for key, value in self.required.items():
if value:
self.logger.debug('DataZilla field: %s (%s)' % (key, value))
if not value:
self.submit_report = False
self.logger.warn('Missing required DataZilla field: %s' % key)
if not self.submit_report:
self.logger.info('Reports will not be submitted to DataZilla')
示例9: __init__
def __init__(self, profile, clean_profile=True, process_class=None, kp_kwargs=None, env=None):
self.clean_profile = clean_profile
self.env = env or {}
self.kp_kwargs = kp_kwargs or {}
self.process_class = process_class or ProcessHandler
self.process_handler = None
self.profile = profile
self.log = mozlog.getLogger('MozRunner')
示例10: main
def main():
parser = OptionParser(usage="%prog <options>")
parser.add_option("--offline", action="store_true", dest="offline", default=False, help="Start without using pulse")
parser.add_option(
"--test-manifest",
action="store",
dest="testmanifest",
default=os.path.join("tests", "all-tests.ini"),
help="Specify the test manifest, defaults to tests/all-tests.ini",
)
parser.add_option(
"--log-file",
action="store",
dest="logfile",
default="b2gautomation.log",
help="Log file to store results, defaults to b2gautomation.log",
)
LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR")
LEVEL_STRING = ", ".join(LOG_LEVELS)
parser.add_option(
"--log-level",
action="store",
type="choice",
dest="loglevel",
default="DEBUG",
choices=LOG_LEVELS,
help="One of %s for logging level, defaults to debug" % LEVEL_STRING,
)
options, args = parser.parse_args()
if not options.testmanifest:
parser.print_usage()
parser.exit()
if not os.path.exists(options.testmanifest):
print "Could not find manifest file: %s" % options.testmanifest
parser.print_usage()
parser.exit()
# Set up the logger
if os.path.exists(options.logfile):
os.remove(options.logfile)
logger = mozlog.getLogger("B2G_AUTOMATION", options.logfile)
if options.loglevel:
logger.setLevel(getattr(mozlog, options.loglevel, "DEBUG"))
try:
b2gauto = B2GAutomation(options.testmanifest, offline=options.offline)
# this is test code
d = b2gauto.install_build("http://10.242.30.20/out/qemu_package.tar.gz")
b2gauto.run_marionette(d)
except:
s = traceback.format_exc()
logger.error(s)
return 1
return 0
示例11: setUp
def setUp(self):
self.logger = mozlog.getLogger('mozprofile.addons')
self.logger.setLevel(mozlog.ERROR)
self.profile = mozprofile.profile.Profile()
self.am = self.profile.addon_manager
self.profile_path = self.profile.profile
self.tmpdir = tempfile.mkdtemp()
示例12: __init__
def __init__(self, options, **kwargs):
self.options = options
self.server = None
self.logger = mozlog.getLogger('PEP')
# create the profile
self.profile = self.profile_class(profile=self.options.profilePath,
addons=[os.path.join(here, 'extension')])
# fork a server to serve the test related files
if self.options.serverPath:
self.runServer()
tests = []
# TODO is there a better way of doing this?
if self.options.testPath.endswith('.js'):
# a single test file was passed in
testObj = {}
testObj['path'] = os.path.realpath(self.options.testPath)
testObj['name'] = os.path.basename(self.options.testPath)
tests.append(testObj)
else:
# a test manifest was passed in
# open and convert the manifest to json
manifest = TestManifest()
manifest.read(self.options.testPath)
tests = manifest.get()
# create a manifest object to be read by the JS side
manifestObj = {}
manifestObj['tests'] = tests
# write manifest to a JSON file
jsonManifest = open(os.path.join(here, 'manifest.json'), 'w')
jsonManifest.write(str(manifestObj).replace("'", "\""))
jsonManifest.close()
# setup environment
env = os.environ.copy()
env['MOZ_INSTRUMENT_EVENT_LOOP'] = '1'
env['MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD'] = str(options.tracerThreshold)
env['MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL'] = str(options.tracerInterval)
env['MOZ_CRASHREPORTER_NO_REPORT'] = '1'
# construct the browser arguments
cmdargs = []
# TODO Make browserArgs a list
cmdargs.extend(self.options.browserArgs)
cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)])
# run with managed process handler
self.runner = self.runner_class(profile=self.profile,
binary=self.options.binary,
cmdargs=cmdargs,
env=env,
process_class=PepProcess)
示例13: setUp
def setUp(self):
self.handler = ListHandler()
self.handler.setFormatter(mozlog.JSONFormatter())
self.logger = mozlog.getLogger('test.Logger')
# Prevents tests from producing output via a default handler.
for h in self.logger.handlers:
self.logger.removeHandler(h)
self.logger.addHandler(self.handler)
self.logger.setLevel(mozlog.DEBUG)
示例14: __init__
def __init__(self, cmd,
args=None, cwd=None,
env=os.environ.copy(),
ignore_children=False,
**kwargs):
ProcessHandler.__init__(self, cmd, args=args, cwd=cwd, env=env,
ignore_children=ignore_children, **kwargs)
self.logger = mozlog.getLogger('PEP')
示例15: __init__
def __init__(self, profile, clean_profile=True, process_class=None, kp_kwargs=None, env=None, symbols_path=None):
self.clean_profile = clean_profile
self.env = env or {}
self.kp_kwargs = kp_kwargs or {}
self.process_class = process_class or ProcessHandler
self.process_handler = None
self.returncode = None
self.profile = profile
self.log = mozlog.getLogger("MozRunner")
self.symbols_path = symbols_path