Oct-19-2017, 03:15 AM
Requirement: print out the command line prompts the user enters into a log file.
Problem: line 38, the prompts don't seem to write to the log file.
Code:
Problem: line 38, the prompts don't seem to write to the log file.
Code:
#! /usr/bin/env python3 import sys import os import argparse import platform import logging if __name__ == "__main__": parser = argparse.ArgumentParser( description='File parsing program') parser.add_argument('-l', '--log_file', default='lab2.log', metavar = ' ', help='Log file', action="store") parser.add_argument('-p', '-parse', metavar = ' ', help="File to parse", required = True, action="store") parser.add_argument('-s', '-string', metavar = ' ', help="String to search", required = True, action="store") args = parser.parse_args() try: logging.basicConfig(filename='lab2.log', level=logging.DEBUG, format= '%(asctime)s,%(message)s', datefmt= '%m/%d/%Y %I:%M:%S %p') #logs date and time logging.debug('The logging occured in: %s ', __name__) #logs name of code logging.info('The program has started!') #prompts start of program logging.info('The command line prompts were: 1) log file = %s, 2) parse = %s, and 3) string = %s ', args.log_file, args.parse, args.string) #logs command line prompts except: print('Could not open log file :(') #error message if file not created