本文整理汇总了Python中output.Output.setup_custom_logger方法的典型用法代码示例。如果您正苦于以下问题:Python Output.setup_custom_logger方法的具体用法?Python Output.setup_custom_logger怎么用?Python Output.setup_custom_logger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类output.Output
的用法示例。
在下文中一共展示了Output.setup_custom_logger方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import setup_custom_logger [as 别名]
def main():
# parse command line options and arguments:
modes=['x','xmlfiles','j','jsonfiles','c','ckandatasets','p','pids','x-p', 'x-j', 'j-c','j-p']
p = options_parser(modes)
options,arguments = p.parse_args()
# check option 'mode' and generate process list:
(mode, pstat) = pstat_init(p,modes,options.mode,options.source,options.host)
# check for quiet mode
if (options.quiet):
qmsg='would be'
mainmode='check'
else:
qmsg='is'
mainmode='deletion'
if options.host :
print "\tCKAN HOST:\t%s" % (options.host)
if options.handle_check :
print "\tCREDENTIAL:\t%s" % (options.handle_check)
print '='*90
# make jobdir
now = time.strftime("%Y-%m-%d %H:%M:%S")
jid = os.getpid()
print "\tStart of processing:\t%s" % (now)
global logger
OUT = Output(pstat,now,jid,options)
##HEW-D logger = log.getLogger()
## logger
logger = OUT.setup_custom_logger('root',options.verbose)
# create credentials if required
if (options.handle_check):
try:
cred = PIDClientCredentials.load_from_JSON('credentials_11098')
except Exception, err:
logger.critical("[CRITICAL] %s Could not create credentials from credstore %s" % (err,options.handle_check))
p.print_help()
sys.exit(-1)
else:
logger.debug("Create EUDATHandleClient instance")
HandleClient = EUDATHandleClient.instantiate_with_credentials(cred,HTTPS_verify=True)
示例2: main
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import setup_custom_logger [as 别名]
def main():
pstat = {
'status' : {},
'text' : {},
'short' : {},
}
now = time.strftime("%Y-%m-%d %H:%M:%S")
jid = os.getpid()
ckanlistrequests=['package_list','group_list','tag_list']
## Get options and arguments
args = get_args(ckanlistrequests)
# Output instance
OUT = Output(pstat,now,jid,args)
logger = OUT.setup_custom_logger('root',args.verbose)
## Settings for CKAN client and API
ckanapi3='http://'+args.iphost+'/api/3'
auth='12345'
CKAN = CKAN_CLIENT(args.iphost,auth)
ckan_limit=500000
start=time.time()
if args.request.endswith('list'):
try:
if args.request == 'community_list' :
action='group_list'
else:
action=args.request
if PY2 :
answer = CKAN.action(action, rows=ckan_limit)
else:
answer = CKAN.action(action)
except ckanclient.CkanApiError as e :
print('\t\tError %s Supported list requests are %s.' % (e,ckanlistrequests))
sys.exit(1)
print('\n\t%s' % '\n\t'.join(answer).encode('utf8'))
sys.exit(0)
# create CKAN search pattern :
ckan_pattern = ''
sand=''
pattern=' '.join(args.pattern)
if (args.community):
ckan_pattern += "groups:%s" % args.community
sand=" AND "
if (args.pattern):
ckan_pattern += sand + pattern
print(' | - Search\n\t|- in\t%s\n\t|- for\t%s\n' % (args.iphost,ckan_pattern))
if args.request == 'package_search' :
if PY2:
answer = CKAN.action('package_search', {"q":ckan_pattern}) ##HEW-D? , rows=ckan_limit)
else:
answer = CKAN.action('package_search',{"q":ckan_pattern})
for key, value in answer.items() :
logger.warning('answer has key %s' % key)
if PY2 :
tcount=answer['result']['count'] ### ['count']
else:
tcount=answer['result']['count']
print(' | - Results:\n\t|- %d records found in %d sec' % (tcount,time.time()-start))
# Read in B2FIND metadata schema and fields
schemafile = '%s/mapfiles/b2find_schema.json' % (os.getcwd())
with open(schemafile, 'r') as f:
b2findfields=json.loads(f.read(), object_pairs_hook=OrderedDict)
if tcount>0 and args.keys is not None :
if len(args.keys) == 0 :
akeys=[]
else:
if args.keys[0] == 'B2FIND.*' :
akeys=OrderedDict(sorted(b2findfields.keys()))
else:
akeys=args.keys
suppid=b2findfields.keys()
fh = io.open(args.output, "w", encoding='utf8')
record={}
totlist=[]
count={}
count['id']=0
statc={}
for outt in akeys:
if outt not in suppid :
print(' [WARNING] Not supported key %s is removed' % outt)
akeys.remove(outt)
else:
count[outt]=0
#.........这里部分代码省略.........
示例3: main
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import setup_custom_logger [as 别名]
def main():
# initialize global settings
settings.init()
# parse command line options and arguments:
modes=['a','g','generate','h','harvest','m','map','v','validate','c','convert','u','upload','h-m','m-u','h-u', 'h-d', 'd','delete']
p = options_parser(modes)
global options
options,arguments = p.parse_args()
# check option 'mode' and generate process list:
(mode, pstat) = pstat_init(p,modes,options.mode,options.source,options.iphost)
# set now time and process id
now = time.strftime("%Y-%m-%d %H:%M:%S")
jid = os.getpid()
# Output instance
OUT = Output(pstat,now,jid,options)
## logger
global logger
logger = OUT.setup_custom_logger('root',options.verbose)
## logger = logging.getLogger('root')
##HEW-D logging.basicConfig(format=log_format, level=log_level) ### logging.DEBUG)
# print out general info:
logger.info('B2FIND Version: \t%s' % settings.B2FINDVersion)
logger.info('Run mode: \t%s' % pstat['short'][mode])
logger.info('Process ID:\t%s' % str(jid))
logger.debug('Processing modes (to be done):\t')
for key in pstat['status']:
if pstat['status'][key] == 'tbd':
logger.debug(" %s\t%s" % (key, pstat['status'][key]))
# check options:
if ( pstat['status']['u'] == 'tbd'):
# checking given options:
if (options.iphost):
if (not options.auth):
from os.path import expanduser
home = expanduser("~")
if(not os.path.isfile(home+'/.netrc')):
logger.critical('Can not access job host authentification file %s/.netrc ' % home )
exit()
f = open(home+'/.netrc','r')
lines=f.read().splitlines()
f.close()
l = 0
for host in lines:
if(options.iphost == host.split()[0]):
options.auth = host.split()[1]
break
logger.debug(
'NOTE : For upload mode write access to %s by API key must be allowed' % options.iphost
)
if (not options.auth):
logger.critical('API key is neither given by option --auth nor can retrieved from %s/.netrc' % home )
exit()
else:
logger.critical(
"\033[1m [CRITICAL] " +
"For upload mode valid URL of CKAN instance (option -i) and API key (--auth) must be given" + "\033[0;0m"
)
sys.exit(-1)
# check options:
if (not(options.handle_check) and pstat['status']['u'] == 'tbd'):
logger.warning("You are going to upload datasets to %s without checking handles !" % (options.iphost))
# write in HTML results file:
OUT.HTML_print_begin()
## START PROCESSING:
logger.info("Start : \t%s\n" % now)
logger.info("Loop over processes and related requests :\n")
logger.debug('|- <Process> started : %s' % "<Time>")
logger.debug(' |- Joblist: %s' % "<Filename of request list>")
logger.debug('\n |# %-15s : %-30s \n\t|- %-10s |@ %-10s |' % ('<ReqNo.>','<Request description>','<Status>','<Time>'))
OUT.save_stats('#Start','subset','StartTime',0)
try:
# start the process:
process(options,pstat,OUT)
sys.exit()
except Exception as err :
logging.critical("%s" % err)
logging.error("%s" % traceback.format_exc())
sys.exit()
finally:
# exit the program and open results HTML file:
exit_program(OUT)
now = time.strftime("%Y-%m-%d %H:%M:%S")
logger.info("End of processing :\t\t%s" % now)
示例4: verbosity
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import setup_custom_logger [as 别名]
usage = "%prog [options] COMMUNITY"
)
p.add_option('-v', '--verbose', action="count", help="increase output verbosity (e.g., -vv is more than -v)", default=False)
p.add_option('--iphost', '-i', help="IP adress of B2FIND portal (CKAN instance)", metavar='IP')
p.add_option('--auth', help="Authentification for CKAN API (API key, by default taken from file $HOME/.netrc)",metavar='STRING')
p.add_option('--jobdir', help='\ndirectory where log, error and html-result files are stored. By default directory is created as startday/starthour/processid .', default=None)
p.add_option('--mode', '-m', metavar='PROCESSINGMODE', help='\nSupported modes are (c)reate, (u)pdate, (patch), (d)elete, (p)urge and (s)how . default is creation of a group', default='c')
options,arguments = p.parse_args()
pstat=dict()
now = time.strftime("%Y-%m-%d %H:%M:%S")
jid = os.getpid()
OUT = Output(pstat,now,jid,options)
logger = OUT.setup_custom_logger('root',options.verbose)
community=sys.argv[1]
conffile='mapfiles/%s.json' % community
with open(conffile, 'r') as f:
group_dict = json.load(f)
# checking given options:
if (not options.iphost):
logger.critical('The option iphost is mandatory !')
sys.exit()
if (not options.auth):
home = os.path.expanduser("~")
if (not os.path.isfile(home+'/.netrc')):