Reputation: 304
I created a special print()
function that simulates how Logging works, but only in the Console. I'd like the color of the text output from these Print()
statements to change based on the output.
Here's an example of a few lines from the Console:
- 2021-12-24 14:49:07 | DEBUG | - Campaign "Test" budget is 250 / 0.
- 2021-12-24 14:49:07 | DEBUG | - Getting sending data for campaign's 2 audiences...
- 2021-12-24 14:49:07 | INFO | - Randomly chose campaign "Test".
- 2021-12-24 14:49:07 | INFO | - Randomly chose audience "etest".
- 2021-12-24 14:49:07 | WARN | - Campaign is missing "Sending Timezone" .
Is it possible to change each row's color in the Console based on the text?
For example, have lines with "WARN" appear in orange; etc...
Upvotes: 0
Views: 734
Reputation: 26
colorama may help.
Example:
from colorama import init, Fore, Style
init()
def print_log(info, level):
if(level == "WARN"):
print(Fore.YELLOW + "[WARN] " + info)
print(Style.RESET_ALL) # Don't forget to change back to normal
print_log("This is a warning", "WARN")
Actually, Fore.YELLOW
send ANSI sequences to console, which can change the color of text in console.
Upvotes: 1