Skip to content

Instantly share code, notes, and snippets.

@vincentscode
Created July 16, 2019 12:43
Show Gist options
  • Save vincentscode/9ea37156e41b4debd1a0613b2c4bb4ee to your computer and use it in GitHub Desktop.
Save vincentscode/9ea37156e41b4debd1a0613b2c4bb4ee to your computer and use it in GitHub Desktop.
log_file = open("log.txt", "w")
# noinspection PyShadowingBuiltins
def print(*args, log_level=0):
if log_level == 0:
log_prefix = "[INFO ] "
elif log_level == 1:
log_prefix = "[WARN ] "
elif log_level == 2:
log_prefix = "[ERROR] "
else:
log_prefix = "[ ] "
print_string = "[" + datetime.now().strftime('%H:%M:%S.%f') + "] " + log_prefix + " ".join(map(str, args)).replace("\n", "")
builtins.print(print_string)
log_file.write(print_string + "\n")
log_file.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment