I have a loop. For each pass of the loop I want to change the name of the logging logfile. The below code takes the first name assigned to the logfile and for each pass of the loop puts all the data for each iteration into this one file:
import logging
global sub_dict
sub_dict = {
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight'
}
def test_func():
for key, value in sub_dict.items():
log_path = ''.join(('C:\\Users\\Oleg Salenko\\AppData\\Local\\WebGrab+Plus\\Addons\\Log Files\\', str(key), '-', str(value), '.log'))
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s :: %(levelname)s :: %(message)s', filename=log_path, filemode='w')
logging.captureWarnings(True)
logger = logging.getLogger(__name__)
try:
logging.info('{}'.format('This is an example...'))
logging.info('{} {}'.format(key, value))
logging.info('{}'.format('Of why concurrent logging into a single file...'))
logging.info('{}'.format('Is a complete an utter mess...'))
except Exception as exc:
print('%r generated an exception: %s' % (new_dict2, exc))
return key, value
test_func()
...what do I need to amend so that each time the loop passes, the logfile name is reassigned correctly?
Thanks