Just wondering how anyone else deals with using a FileLogger in their plugin and what they do when they have multiple instances of the plugin instantiated/running… obviously I need to have separate names for the logs for each instance… but was wondering how others deal with this…?
No, each instance has it’s own FileLogger and separate log file… for now I’m using FileLogger::createDateStampedLogger() so they have separate files… but I’ll need to write a cleanup method to delete any logs older than 24 hours (or if the number of logs exceeds an arbitrary value I’ll have to decide on)…
I was interested to see what other devs may have done.
hum.. the shared object class needs a public default constructor, but there's no way to set the 'fileToWriteTo' of a FileLogger after it has been constructed. So how can I do? Am I missing something simple/thinking the wrong way?
also, perhaps it's fine, but it sounds a bit weird to me to have a SharedResourcePointer<MyFileLogger> when Logger itself has a static Logger* currentLogger
I think the idea is to have a shared instance of your own class and just use the reference count value and append that to the FileLogger name when you create the FileLogger… Or something like that… Just woke up
Ok, so what would you recommended to share a FileLogger between plugin's instances? anything special to care about ? (will the current static Logger* currentLogger be a problem?)
and I'm not sure when/how to call setCurrentLogger (nullptr)
Couldn’t you have your own SharedResourcePointer derived class and in its destructor setCurrentLogger(nullptr) ?
What you’re trying to do is different to me… The problem I see in using a shared file for all the instances is having to know which instance is logging what… So you’d have to prepend each log entry with an id.
class CLogCounter
{
public:
CLogCounter();
~CLogCounter();
int addLog();
int removeLog();
int getCount() { return m_iCount; }
private:
int m_iCount;
};
CLogCounter::CLogCounter() : m_iCount (0)
{
}
CLogCounter::~CLogCounter()
{
}
int CLogCounter::addLog()
{
++m_iCount;
return m_iCount;
}
int CLogCounter::removeLog()
{
--m_iCount;
if (m_iCount < 0)
m_iCount = 0;
return m_iCount;
}
In my main processor class I declared a public SharedResourcePointer:
SharedResourcePointer<CLogCounter> m_pLogCounter;
and in the constructor before naming the FileLogger I get the instance number:
I was saying that because of the instances number that you use for the filenames :
if the user loads 2 instances of your plug, one as VST and one as AU, both will get the same 'instance' number, so the same log file name if you just use the instance number in there.
Aah... Hadn't checked that... Good call... There are other edge cases as well so I'm still sticking to using the date/time stamped file names right now...
I just came across this thread since I'm trying to solve the same problem: I want the different instances of my plugin to use different FileLoggers. There is just one remaining problem: How do you associate each instance of the plugin to a separate logger when you have multiple instances running at the same time? The setCurrentLogger method is static. If I do something like this in my processor class:
Logger::setCurrentLogger(log_file_);
Then all running instances will redirect their logging to the log file of the last instance. What's the workaround?
The solution is simpler than I thought: I shouldn't use setCurrentLogger at all, neither for setting nor removing the logger. I can just use the logMessage method directly on a FileLogger member of each processor.
I must have been slightly confused by by the two different questions discussed in this thread.