Logging
print("here") never gets old...
Using print()
statements are okay for debugging, but it quickly leads to a mess of log messages which makes debugging increasing difficult as the here!!!
that you're searching for gets buried by a mountain of other similarly-ambiguous messages (we've all been there). As you slowly move to make your bot production-ready, simply using print()
s for logging isn't sustainable. Many logging packages were created precisely to solve this problem, providing semantic logging and logging to various transports (not just your console).
SwiftLog
A logging solution for Swift built by Apple themselves, it's a perfect solution for logging in Swift. Being both lightweight and providing a wide variety of logging transports, it's the logging solution I'd recommend for your Swift Discord bot. An example of a "kitchen sink" Discord bot built with DiscordKit that also uses SwiftLog is available in this repository.
Semantic Logging
Using a dedicated logging solution is definitely an improvement over littering print()
s everywhere, but logs that do not follow a specific style are also difficult to analyse and interpret with utilities. I'd strongly recommend following semantic logging guidelines for the cleanest logs.
What About DiscordKit?
Well, I'd be quite the hypocrite to recommend these practices and not follow them myself. Thankfully, DiscordKit itself fully uses SwiftLog for all logging and follows Semantic Logging as far as possible! You might notice that logging messages from DiscordKit look a little different, now you know why!
Last updated