以下代码:
logging.info('Collecting available features for location ' + source_feature['properties']['key'] + ' and date range [' + start_date + '..' + end_date + ']...')
feature_start_time = datetime.now()
target_directory = util.target_directory(source_feature['properties'])
if target_directory is None:
target_directory = util.target_directory_for_point(point)
try:
for layer in layers:
logging.info('Layer: \'' + layer + '\'')
print('Found dates: ', end='', flush=True)
criterion_date = end_date
while criterion_date is not None:
打印出类似于这样的内容
Found dates: 20170630130831 Collecting available features for location 8404222738792 and date range [2016-04-16..2017-06-30]...
20170630130831 Layer: '1_NATURAL_COL0R'
2017-06-22 2017-05-13 2017-04-23 2017-04-03 2017-03-14 2017-02-22 2017-01-23 2016-11-24 2016-10-05 2016-08-06 2016-07-17 2016-06-27 2016-06-07
即打印输出与记录器输出交替出现。
如何进行同步?我希望日志在被调用时立即打印,而不会与打印内容混合。
更新
以下是初始化日志记录的内容:
import logging
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%Y%m%d%H%M%S', level=logging.INFO)
logging.Handler().flush()
,这样可以吗? - Chris_Rands