Hi,
I’m new to Juce, and I am currently working through Getting Started with JUCE by Martin Robinson. The first example in chapter 3 aims to log “Hello world!” to the console with this code:
However, nothing logs to the console. I added an if statement to check if getCurrentLogger() is returning a nullptr and, sure enough, it is.
Has there been a change in the JUCE framework that would cause this issue (the book is from 2012)? How do I go about setting the current logger so it isn’t a nullptr? I understand this is basic stuff, but having trouble finding a solution via Google.
Call ::setCurrentLogger and the beginning of your app (and for good measures ::setCurrentLogger(nullptr) before shutdown, I think there is also an assert for it).
JUCE has a pretty decent implementation ready that logs into a file: JUCE: FileLogger Class Reference
Make sure to create that in a unique_ptr. ::setCurrentLogger won’t take ownership. If you don’t destruct the file logger properly, you might end up with some hard to track bugs where log messages falling through at the applications shutdown time.
I think under debug builds, ::writeToLog always also logs into the console.
If that is the same book available from Amazon as the first Google result, that seems to now be over 10 years old, so lot’s of stuff in that is going to be out of date.
I have cloned all of these repos and update them every week, watching the progress on a huge set of JUCE projects out there in open-source land … and it is without doubt one of the nicest ways to keep abreast of JUCE development. Watching everyone elses progress is also very inspirational…