16 lines
504 B
Python
16 lines
504 B
Python
#!/usr/bin/env python3
|
|
|
|
|
|
def get_logger(source_file, log_dir='logs'):
|
|
import logging
|
|
import os
|
|
source_file = os.path.split(source_file)[-1]
|
|
log_format = '[%(asctime)s] %(module)s:%(lineno)s %(message)s'
|
|
logging.basicConfig(format=log_format)
|
|
log = logging.getLogger()
|
|
log.setLevel(logging.DEBUG)
|
|
file_handler = logging.FileHandler(f'{log_dir}/{source_file}.log')
|
|
file_handler.setFormatter(logging.Formatter(log_format))
|
|
log.addHandler(file_handler)
|
|
return log
|