Created
July 27, 2018 01:06
-
-
Save enijkamp/f0296f3dd62e6cc87cdf7805de0ee574 to your computer and use it in GitHub Desktop.
experiments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def copy_source(file, output_dir): | |
copyfile(file, os.path.join(output_dir, os.path.basename(file))) | |
def setup_logging(output_dir): | |
log_format = logging.Formatter("%(asctime)s : %(message)s") | |
logger = logging.getLogger() | |
logger.handlers = [] | |
output_file = os.path.join(output_dir, 'output.log') | |
file_handler = logging.FileHandler(output_file) | |
file_handler.setFormatter(log_format) | |
logger.addHandler(file_handler) | |
console_handler = logging.StreamHandler(sys.stdout) | |
console_handler.setFormatter(log_format) | |
logger.addHandler(console_handler) | |
logger.setLevel(logging.INFO) | |
def get_output_dir(exp_id): | |
t = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') | |
output_dir = os.path.join('output/' + exp_id, t) | |
if not os.path.exists(output_dir): | |
os.makedirs(output_dir) | |
return output_dir | |
exp_id = os.path.splitext(os.path.basename(__file__))[0] | |
output_dir = get_output_dir(exp_id) | |
copy_source(__file__, output_dir) | |
setup_logging(output_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment