Skip to content

Commit

Permalink
Refactor start_time assignment in log_analyzer.py to use today - 7 da…
Browse files Browse the repository at this point in the history
…ys if not provided
  • Loading branch information
pgyogesh committed Apr 24, 2024
1 parent 72b8267 commit 78229cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions log_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def _format_args(self, action, default_metavar):
# 7 days ago from today
seven_days_ago = datetime.datetime.now() - datetime.timedelta(days=7)
seven_days_ago = seven_days_ago.strftime("%m%d %H:%M")

# If not start time then set it to today - 3 days in "MMDD HH:MM" format
# If not start time then set it to today - 7 days in "MMDD HH:MM" format
start_time = datetime.datetime.strptime(args.start_time, "%m%d %H:%M") if args.start_time else datetime.datetime.strptime(seven_days_ago, "%m%d %H:%M")
end_time = datetime.datetime.strptime(args.end_time, "%m%d %H:%M") if args.end_time else None

Expand Down Expand Up @@ -113,8 +112,13 @@ def _format_args(self, action, default_metavar):
log_file = 'analyzer.log'
file_handler = logging.FileHandler(log_file)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)

# Log times
logger.info("Start Time: " + str(start_time))
logger.info("End Time: " + str(end_time))

# Define lock for writing to file
lock = Lock()

Expand Down

0 comments on commit 78229cd

Please sign in to comment.