I'm looking to create a log file for my discord bot which is built with python.
I have a few set of commands which output the console through the print command, I have added a date and time to the print outputs so it can be tracked when the bot is running. However, is it easy to make it save the print outs to a file as well? That way I can make a log file to track different days and what was called for.
Console Output: Screenshot_1.png
Example of a print command in my code:
async def coin(ctx):
author = ctx.message.author
choice = random.randint(1,2)
if choice == 1:
await bot.say("Heads")
print(currentTime() + " - Coin Requested by " + str(author) + " It Landed on Heads!")
elif choice == 2:
await bot.say("Tails")
print(currentTime() + " - Coin Requested by " + str(author) + " It Landed on Tails!")
I have tried looking online at some other questions but I get quite confused looking at them as there is no clear explanation as to what is happening and how I can configure it to work for my code.