本文整理汇总了Python中systematic.log.Logger.set_level方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.set_level方法的具体用法?Python Logger.set_level怎么用?Python Logger.set_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类systematic.log.Logger
的用法示例。
在下文中一共展示了Logger.set_level方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Script
# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import set_level [as 别名]
#.........这里部分代码省略.........
"""Add a subcommand parser instance
Register named subcommand parser to argument parser
Subcommand parser must be an instance of ScriptCommand class.
Example usage:
class ListCommand(ScriptCommand):
def run(self, args):
print 'Listing stuff'
parser.add_subcommand(ListCommand('list', 'List stuff from script'))
"""
if self.subcommand_parser is None:
self.subcommand_parser = self.parser.add_subparsers(
dest='command', help='Please select one command mode below',
title='Command modes'
)
self.subcommands = {}
if not isinstance(command, ScriptCommand):
raise ScriptError('Subcommand must be a ScriptCommand instance')
parser = self.subcommand_parser.add_parser(
command.name,
help=command.short_description,
description=command.description,
epilog=command.epilog,
formatter_class=argparse.RawTextHelpFormatter,
)
self.subcommands[command.name] = command
command.script = self
return parser
def usage_error(self, *args, **kwargs):
return self.parser.error(*args, **kwargs)
def add_argument(self, *args, **kwargs):
"""
Shortcut to add argument to main argumentparser instance
"""
self.parser.add_argument(*args, **kwargs)
def parse_args(self):
"""
Call parse_args for parser and check for default logging flags
"""
args = self.parser.parse_args()
if hasattr(args, 'debug') and getattr(args, 'debug'):
self.logger.set_level('DEBUG')
elif hasattr(args, 'quiet') and getattr(args, 'quiet'):
self.silent = True
elif hasattr(args, 'verbose') and getattr(args, 'verbose'):
self.logger.set_level('INFO')
if self.subcommand_parser is not None:
self.subcommands[args.command].run(args)
return args
def execute(self, args, dryrun=False):
"""
Default wrapper to execute given interactive shell command
with standard stdin, stdout and stderr
"""
if isinstance(args, basestring):
args = args.split()
if not isinstance(args, list):
raise ValueError('Execute arguments must be a list')
if dryrun:
self.log.debug('would execute: %s' % ' '.join(args))
return 0
p = Popen(args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
p.wait()
return p.returncode
def check_output(self, args):
"""
Wrapper for subprocess.check_output to be executed in script context
"""
if isinstance(args, basestring):
args = [args]
try:
return check_output(args)
except IOError, (ecode, emsg):
raise ScriptError(emsg)
except OSError, (ecode, emsg):
raise ScriptError(emsg)
示例2: Script
# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import set_level [as 别名]
#.........这里部分代码省略.........
)
self.subcommands = {}
if not isinstance(command, ScriptCommand):
raise ScriptError('Subcommand must be a ScriptCommand instance')
parser = self.subcommand_parser.add_parser(
command.name,
help=command.short_description,
description=command.description,
epilog=command.epilog,
formatter_class=argparse.RawTextHelpFormatter,
)
self.subcommands[command.name] = command
command.script = self
if callable(getattr(command, '__register_arguments__', None)):
command.__register_arguments__(parser)
return parser
def usage_error(self, *args, **kwargs):
return self.parser.error(*args, **kwargs)
def add_argument(self, *args, **kwargs):
"""
Shortcut to add argument to main argumentparser instance
"""
self.parser.add_argument(*args, **kwargs)
def __process_args__(self, args):
"""Process args
Process args from parse_*args CalledProcessError
"""
if getattr(args, 'debug', None):
self.logger.set_level('DEBUG')
elif getattr(args, 'quiet', None):
self.silent = True
elif getattr(args, 'verbose', None):
self.logger.set_level('INFO')
if self.subcommand_parser is not None and args.command is not None:
if hasattr(self.subcommands[args.command], 'parse_args'):
args = self.subcommands[args.command].parse_args(args)
self.subcommands[args.command].run(args)
return args
def parse_args(self):
"""
Call parse_args for parser and check for default logging flags
"""
return self.__process_args__(self.parser.parse_args())
def parse_known_args(self):
"""
Call parse_args for parser and check for default logging flags
"""
args, other_args = self.parser.parse_known_args()
args = self.__process_args__(args)
return args, other_args
def execute(self, args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, dryrun=False):
"""
Default wrapper to execute given interactive shell command
with standard stdin, stdout and stderr
"""
if isinstance(args, str):
args = args.split()
if not isinstance(args, list):
raise ValueError('Execute arguments must be a list')
if dryrun:
self.log.debug('would execute: {0}'.format(' '.join(args)))
return 0
p = Popen(args, stdin=stdin, stdout=stdout, stderr=stderr)
p.wait()
return p.returncode
def check_output(self, args):
"""
Wrapper for subprocess.check_output to be executed in script context
"""
if isinstance(args, str):
args = [args]
try:
return check_output(args)
except IOError as e:
raise ScriptError(e)
except OSError as e:
raise ScriptError(e)
except CalledProcessError as e:
raise ScriptError(e)