本文整理汇总了Python中utils.logger.Logger.instance方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.instance方法的具体用法?Python Logger.instance怎么用?Python Logger.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.logger.Logger
的用法示例。
在下文中一共展示了Logger.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_element
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def build_element(link_type, label):
# find item which is desired
link_text = None
if label.find(':') != -1:
link_text = label[label.find(':') + 1:]
label = label[:label.find(':')]
result = Globals.get_url_by_name(label, link_type)
item = result[0]
item_field = result[1]
a = etree.Element('a')
a.set('data-href', 'Alink')
if item_field:
a.text = link_text or item_field.href_name
a.set('href', '#{item_field.href_id}'.format(item_field=item_field))
elif item:
a.text = link_text or item.href_name
a.set('href', '#{item.href_id}'.format(item=item))
else:
Logger.instance().warning('Link not found %s %s' % (link_type, label))
return ''
a.set('text', a.text)
return a
示例2: _run
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def _run(self, timeout):
timeout = min([max_wait_time, timeout]) * self.scale
def target():
Logger.instance().info('Running command with time limit {:1.2f} s: {} in {}'.format(timeout, self.args.command, self.args.cwd))
self.process = Popen(self.args.command, stdout=self.out, stderr=self.err, stdin=self.inn, cwd=self.args.cwd)
Logger.instance().info('started PID {}'.format(self.process.pid))
self.process.wait() # process itself is not limited but there is global limit
Logger.instance().info('Command finished with %d' % self.process.returncode)
thread = threading.Thread(target=target)
thread.start()
thread.join(GlobalTimeout.time_left())
if thread.is_alive():
Logger.instance().info('Terminating process')
self.terminated = True
self.global_terminate = GlobalTimeout.time_left() < 0
try:
self.process.terminate()
except Exception as e:
print(e)
try:
self.process.kill()
except Exception as e:
print(e)
thread.join()
示例3: save
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def save(key, item):
if key in Globals.items:
Logger.instance().info('duplicate key %s' % key)
for i in range(2, 100):
new_key = '{}-{}'.format(key, i)
if new_key not in Globals.items:
Logger.instance().info('For key %s assigned %s' % (key, new_key))
Globals.items[new_key] = item
return new_key
Globals.items[key] = item
return key
示例4: get
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def get(self, *args):
"""
Method will return first matching valid property of this object
:param args: list[str]
:return:
"""
for arg in args:
value = getattr(self, arg, None)
if value:
return value
Logger.instance().debug('Cannot find {args} on {self}'.format(args=args, self=self))
return None
示例5: format
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def format(self, record_key, record):
"""
:type record: ist.nodes.TypeRecord
:type record_key: ist.extras.TypeRecordKey
"""
reference = record_key.type.get_reference()
# try to grab formatter and format type and default value based on reference type
try:
fmt = HTMLFormatter.get_formatter_for(reference)
fmt.format_as_child(reference, record_key, record)
self.add(fmt.current())
except NotImplementedException as e:
Logger.instance().info(' <<Missing formatter for {}>>'.format(type(reference)))
示例6: parse_args
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def parse_args(parser):
"""Parses argument using given parses and check resulting value combination"""
(options, args) = parser.parse_args()
if options.input is None:
Logger.instance().warning("Error: No input file specified!")
parser.print_help()
sys.exit(1)
if options.output is None:
Logger.instance().warning("Error: No output file specified!")
parser.print_help()
sys.exit(1)
return options, args
示例7: process_file
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def process_file(self, file_path):
"""
Process single file
:param file_path:
:return:
"""
Logger.instance().info('Processing {:s}'.format(file_path))
with open(file_path, 'r') as fp:
file_content = fp.read()
file_content = file_content.lstrip()
li_start, li_end = self.find_license(file_content)
if li_start == 0 and li_end == 0:
if self.replace_only:
Logger.instance().info('File {:s} skipped, no license found'.format(file_path))
return
if li_start is not None and li_end is not None:
old_license = file_content[li_start:li_end]
file_content = file_content[li_end:].lstrip()
variables = self.variables.copy()
variables.update(
{
'filepath': file_path,
'filename': os.path.basename(file_path),
'datetime': datetime.datetime.now()
})
if self.old_variables:
self.add_old_variables(variables, old_license)
if self.git:
variables.update({
'last_change': self._secure_output('git log -1 --format=%cd ' + file_path),
'last_author': self._secure_output('git log -1 --format=%cn ' + file_path),
'last_email': self._secure_output('git log -1 --format=%ce ' + file_path)
})
license_text = self.license_text.strip() if self.whitespace else self.license_text
license_text = license_text.format(**variables)
with open(file_path, 'w') as fp:
if license_text:
fp.write(license_text)
if self.whitespace:
fp.write('\n\n')
fp.write(file_content)
示例8: format
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def format(self, record_key, record):
"""
:type record: ist.nodes.TypeRecord
:type record_key: ist.extras.TypeRecordKey
"""
tex = texlist()
reference = record_key.type.get_reference()
# try to grab formatter and format type and default value based on reference type
fmt = LatexFormatter.get_formatter_for(reference)
if not fmt:
Logger.instance().info(' <<Missing formatter for {}>>'.format(type(reference)))
else:
tex.extend(fmt.format_as_child(reference, record_key, record))
return tex
示例9: run
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def run(self):
Langs.init(os.path.join(Config.config_dir, 'langs.yaml'))
Problems.init(os.path.join(Config.config_dir, 'problems.yaml'))
while True:
jobs = self.get_jobs()
if jobs:
Logger.instance().info('{} job/s found'.format(len(jobs)))
for job in jobs:
Logger.instance().info('Processing {}'.format(job))
try:
# delete file to let PHP now we are working on it
os.unlink(job.delete_me_file)
result = JobControl.process(job)
except ProcessException as e:
result = e.info
except Exception as e:
result = dict(
result=JobCode.UNKNOWN_ERROR,
error=str(e),
)
# add info about result
self.save_result(job, result)
else:
Logger.instance().debug('no jobs found')
time.sleep(runner_sleep)
示例10: __init__
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def __init__(self, config_json=None):
super(TGHProcessor, self).__init__(name='tgh-processor', pidfile=runner_pidfile)
if not config_json:
return
with open(config_json, 'r') as fp:
self.config = json.load(fp)
Config.watch_dir = self.config['jobs']
Config.problems = self.config['problems']
Config.data = self.config['data']
Config.config_dir = self.config['config']
Config.log_file = self.config['log_file']
logging.root.setLevel(logging.INFO)
Logger._global_logger = Logger(
name='ROOT',
stream_level=logging.DEBUG,
file_level=logging.INFO,
fmt=Logger.default_format,
log_file=Config.log_file
)
Logger.instance().info('Logging on')
示例11: process_body
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def process_body(self, json, level):
"""Recursive body processing"""
# first occurrence of cumul-time-sum is whole-program's measured time
if self.totalDurationMeasured is None and "cumul-time-sum" in json:
self.totalDurationMeasured = json['cumul-time-sum']
if level > 0:
abs_prc = (json["cumul-time-sum"] / self.totalDurationMeasured) * 100
rel_prc = json["percent"]
path = json["file-path"]
if str(json["file-path"]).startswith(self.styles.remove_prefix):
path = path[len(self.styles.remove_prefix):]
# safe average
if (json["call-count-sum"] != 0):
avg_cumul_time = json["cumul-time-sum"] / json["call-count-sum"]
else:
avg_cumul_time = json["cumul-time-sum"]
# safe min max ratio
cumul_time_max = max(json["cumul-time-max"], json["cumul-time-min"])
cumul_time_min = min(json["cumul-time-max"], json["cumul-time-min"])
if (json["cumul-time-max"] > 0):
min_max_ratio = cumul_time_min / cumul_time_max
else:
min_max_ratio = 0
self.append_to_body((
("<", "{abs_prc:6.2f} {leading} {rel_prc:5.2f} {tag}".format(
abs_prc=abs_prc, leading=self.styles.leading_char * (level - 1), rel_prc=rel_prc, tag=json["tag"])),
("^", "{:d}".format(json["call-count-max"])),
("^", "{:1.4f}".format(json["cumul-time-max"])),
("^", "{:1.4f}".format(min_max_ratio)),
("^", "{:1.4f}".format(avg_cumul_time)),
("^", "{:1.4f}".format(json["cumul-time-sum"])),
("<", "{path:s}, {function:s}()".format(function=json["function"], path=path)),
("^", "{line:5d}".format(line=json["file-line"]))
))
if 'children' in json:
for child in json["children"]:
try:
self.process_body(child, level + 1)
except Exception as e:
import json as j
if 'children' in child:
del child['children']
child_repr = j.dumps(child, indent=4)
Logger.instance().warning(
'Caught exception while processing profiler data: {e}'.format(e=e.message))
Logger.instance().warning('Exception', exc_info=e)
Logger.instance().warning('problem node (without children) is:\n{child}'.format(child=child_repr))
示例12: get_max_result
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def get_max_result(cls, result):
"""
Extract result from all cases - GLOBAL_TIMEOUT and SKIPPED and
return max value (or UNKNOWN_ERROR if nothings left)
:rtype: jobs.job_control.JobCode.L
"""
try:
# all results
results = {x for x in plucklib.pluck(result, 'result')}
Logger.instance().info('Statuses = {}'.format(results))
# filtered
results -= {JobCode.GLOBAL_TIMEOUT, JobCode.SKIPPED}
Logger.instance().info('Filtered = {}'.format(results))
# max result
max_result = max(results)
Logger.instance().info('max = {}'.format(max_result))
except Exception as e:
Logger.instance().info('max_status exception = {}'.format(e))
max_result = JobCode.UNKNOWN_ERROR
return max_result
示例13: format
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def format(items):
tex = TexList()
Logger.instance().info('Processing items...')
for item in items:
# do no format certain objects
if not item.include_in_format():
Logger.instance().info(' - item skipped: %s' % str(item))
continue
Logger.instance().info(' - formatting item: %s' % str(item))
# l = LatexRecord()
# l.format(item)
# print l
# exit()
fmt = LatexFormatter.get_formatter_for(item)
if fmt is not None:
fmt.format(item)
tex.extend(fmt)
return tex
示例14: convert
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def convert(self, json_location, output_file=None, formatter="SimpleTableFormatter", styles=[]):
"""Converts file @ json_location to output_file (if set) using given formatter name"""
# read file to JSON
Logger.instance().info('Processing file "%s"', json_location)
if not os.path.exists(json_location):
Logger.instance().error('File "%s" does not exists', json_location)
raise IOError('Empty json file {:s}'.format(json_location))
try:
with open(json_location, 'r') as fp:
json_data = json.load(fp, encoding="utf-8", cls=ProfilerJSONDecoder)
if not json_data:
Logger.instance().error('Empty json file "%s"', json_location)
raise IOError('Empty json file {:s}'.format(json_location))
if 'program-name' not in json_data:
Logger.instance().error('No "program-name" field in json file "%s"', json_location)
raise IOError('No "program-name" field in json file {:s}'.format(json_location))
if json_data['program-name'] != 'Flow123d':
Logger.instance().debug(str(json_data))
Logger.instance().warning('File "%s" does not exists', json_location)
except Exception as ex:
# return string with message on error
Logger.instance().exception('Error while parsing json file ' + json_location, ex)
Logger.instance().error("File size: %d %s", os.stat(json_location).st_size, str(os.stat(json_location)))
raise ex
try:
# split styles fields declaration
styles = [value.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r') for value in styles]
styles = dict(item.split(":", 1) for item in styles)
# grab instance and hand over styles
instance = ProfilerFormatter.get_class_instance(formatter)
instance.set_styles(styles)
# format json object
output = instance.format(json_data)
except Exception as ex:
# return string with message on error
Logger.instance().exception('Error while formatting file ' + json_location, ex)
raise ex
try:
# if output file is specified write result there
if output_file is not None:
with open(output_file, "w") as fp:
fp.write(output)
Logger.instance().info('File "%s" generated', output_file)
# otherwise just print result to stdout
else:
print output
except Exception as ex:
# return string with message on error
Logger.instance().exception('Cannot save file ' + output_file, ex)
raise ex
return True
示例15: main
# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import instance [as 别名]
def main():
"""
Run main program
"""
parser = create_parser()
options, args = parse_args(parser)
# create instance of formatter
from ist.ist_formatter_module import ISTFormatter
formatter = ISTFormatter()
# read input json file
with open(options.input, 'r') as fp:
json_data = json.load(fp)
ist_info = {
'version': json_data['version']['flow123d_version'] if 'version' in json_data else 'Input reference'
}
json_data = json_data['ist_nodes'] if 'ist_nodes' in json_data else json_data
# filter out unsupported types, they won't be formatted
items = list()
for json_item in json_data:
input_type = json_item['input_type'] if 'input_type' in json_item else None
if input_type in registered_nodes:
item = registered_nodes[input_type]()
item.parse(json_item)
items.append(item)
else:
Logger.instance().info(' - item type not supported: %s' % str(item))
# if we have all items parsed we create references
for item in items:
if getattr(item, 'input_type', InputType.UNKNOWN) == InputType.MAIN_TYPE:
if item.input_type == InputType.RECORD:
for key in getattr(item, 'keys', []):
if key.type.get_reference().input_type == InputType.ARRAY:
key.type.get_reference().subtype.get_reference().add_ref(item)
else:
key.type.get_reference().add_ref(item)
if item.input_type == InputType.ABSTRACT_RECORD:
for imp in getattr(item, 'implementations', []):
imp.get_reference().add_ref(item)
# sort items by type and name
items = sorted(items, key=lambda x: '{}{}'.format(x.input_type.value, x.name))
# convert to tex format
if options.format.lower() in ('tex', 'latex'):
Logger.instance().info('Formatting ist to tex format')
from ist.utils.texlist2 import TexList
TexList.PRETTY_FORMAT = options.debug
formatter.json2latex(items, options.output, info=ist_info)
if os.path.isfile(options.output):
print('Ok: File "{:s}" created'.format(options.output))
sys.exit(0)
else:
print('Error: File "{:s}" does not exists'.format(options.output))
sys.exit(1)
# convert to HTML format
if options.format.lower() in ('html', 'html5', 'www', 'htm'):
Logger.instance().info('Formatting ist to html format')
formatter.json2html(items, options.output, info=ist_info)
if os.path.isfile(options.output):
print('Ok: File "{:s}" created'.format(options.output))
sys.exit(0)
else:
print('Error: File "{:s}" does not exists'.format(options.output))
sys.exit(1)
if options.format.lower() in ('markdown', 'md'):
Logger.instance().info('Testing markdown')
text = '''
# Using markdown in description
**Description field** supports markdown syntax (support is partial and some techniques may not work in Python markdown implementation).
## Links
Link to record [[root]] selection [[DG_output_fields]] or abstract [[Transport]]. All links are in the same format.
If `link_name` is specified in `attributes` (let say DG_output_fields has link_name of DG), we can use that [[DG]]
Record and Selection types offer links to their keys/values, so you can write [[DG#porosity]], to specify link text use following syntax [[DG#porosity:poro]]
or link to key in Root item [[root#flow123d_version]]
Every name should be unique, if `link_name` is duplicate first occurrence will be used!
To avoid conflict with `link_name` or `name` we can use type specification like this [[record#root]]. 3 types are registered:
1. type RECORD supporting prefixes:
- r
- record
2. type SELECTION supporting prefixes:
- s
#.........这里部分代码省略.........