Here are the examples of the python api utils.logging_utils.prepare_logging taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
12 Examples
3
Example 1
def CMDconfig(_args):
"""Prints the config.json embedded in this zip."""
logging_utils.prepare_logging(None)
from bot_code import bot_main
json.dump(bot_main.get_config(), sys.stdout, indent=2, sort_keys=True)
print('')
return 0
3
Example 2
def CMDrestart(_args):
"""Utility subcommand that hides the difference between each OS to reboot
the host."""
logging_utils.prepare_logging(None)
import os_utilities
# This function doesn't return.
os_utilities.restart()
# Should never reach here.
return 1
3
Example 3
def CMDsetup(_args):
"""Setup the bot to auto-start but doesn't start the bot."""
logging_utils.prepare_logging(os.path.join('logs', 'bot_config.log'))
from bot_code import bot_main
bot_main.setup_bot(True)
return 0
3
Example 4
def CMDserver(_args):
"""Prints the server url. It's like 'config' but easier to parse."""
logging_utils.prepare_logging(None)
from bot_code import bot_main
print bot_main.get_config()['server']
return 0
3
Example 5
def CMDstart_bot(args):
"""Starts the swarming bot."""
logging_utils.prepare_logging(os.path.join('logs', 'swarming_bot.log'))
logging.info(
'importing bot_main: %s, %s', THIS_FILE, zip_package.generate_version())
from bot_code import bot_main
adb_logger = logging.getLogger('adb')
logging_utils.prepare_logging(os.path.join('logs', 'adb.log'),
adb_logger)
adb_logger.setLevel(logging.DEBUG)
for child in ('high', 'low', 'usb', 'cmd'):
adb_logger.getChild(child).setLevel(logging.DEBUG)
adb_logger.propagate = False
result = bot_main.main(args)
logging.info('bot_main exit code: %d', result)
return result
3
Example 6
def CMDstart_slave(args):
"""Ill named command that actually sets up the bot then start it."""
# TODO(maruel): Rename function.
logging_utils.prepare_logging(os.path.join('logs', 'bot_config.log'))
parser = optparse.OptionParser()
parser.add_option(
'--survive', action='store_true',
help='Do not reboot the host even if bot_config.setup_bot() asked to')
options, args = parser.parse_args(args)
try:
from bot_code import bot_main
bot_main.setup_bot(options.survive)
except Exception:
logging.exception('bot_main.py failed.')
logging.info('Starting the bot: %s', THIS_FILE)
return common.exec_python([THIS_FILE, 'start_bot'])
3
Example 7
def test_prepare_logging(self):
root = logging.RootLogger(logging.DEBUG)
filepath = os.path.join(self.tmp, 'test.log')
logging_utils.prepare_logging(filepath, root)
root.debug('foo')
with open(filepath, 'rb') as f:
result = f.read()
# It'd be nice to figure out a way to ensure it's properly in UTC but it's
# tricky to do reliably.
expected = _LOG_HEADER + ' D: foo\n$'
self.assertTrue(re.match(expected, result), (expected, result))
3
Example 8
def test_rotating_phase_1():
logging_utils.prepare_logging('shared.log')
logging.info('Parent1')
r = call('test_rotating_phase_2', None)
logging.info('Parent2')
return r
3
Example 9
def test_rotating_phase_2():
# Simulate rotating the log.
logging_utils.prepare_logging('shared.log')
logging.info('Child1')
os.rename('shared.log', 'shared.1.log')
logging.info('Child2')
return 0
0
Example 10
def CMDshell(args):
"""Starts a shell with api.* in.."""
logging_utils.prepare_logging(None)
logging_utils.set_console_level(logging.DEBUG)
from bot_code import bot_main
from api import os_utilities
from api import platforms
local_vars = {
'bot_main': bot_main,
'json': json,
'os_utilities': os_utilities,
'platforms': platforms,
}
# Can't use: from api.platforms import *
local_vars.update(
(k, v) for k, v in platforms.__dict__.iteritems()
if not k.startswith('_'))
if args:
for arg in args:
exec code.compile_command(arg) in local_vars
else:
code.interact(
'Locals:\n ' + '\n '.join( sorted(local_vars)), None, local_vars)
return 0
0
Example 11
def CMDtask_runner(args):
"""Internal command to run a swarming task."""
logging_utils.prepare_logging(os.path.join('logs', 'task_runner.log'))
from bot_code import task_runner
return task_runner.main(args)
0
Example 12
def CMDversion(_args):
"""Prints the version of this file and the hash of the code."""
logging_utils.prepare_logging(None)
print zip_package.generate_version()
return 0