I was making an application and willing to pass FileLogger
object to Logger::setCurrentLogger()
. Then suddenly, a warning popped into my head. “Thread safety?”.
Let me ask if what I describe below is correct or not…
When JUCEApplicationBase::moreThanOneInstainceAllowed()
returns always true, I should pass a logger class(Inherited from juce::Logger
) that has static CriticalSection
object (and that will lock in Logger::logMessage()
) as a member variable even if I don’t call Logger::writeToLog()
except in main thread, because juce::Logger
has static Logger pointer object, that will be shared in all application instances, which means more than a thread will access to the object, and that means it needs static lock.
If so, I should make custom logger class instead of FileLogger
class, because FileLogger
class has non-static CriticalSection
.