Created
July 16, 2019 12:43
-
-
Save vincentscode/9ea37156e41b4debd1a0613b2c4bb4ee to your computer and use it in GitHub Desktop.
This file contains 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
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