DefaultAppLogger and multiple instances of plugin

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…?

Cheers,

Rail

3 Likes

I'm interested in that too!

So you don't share the same logger between all your instances?

With what solution did you end up with ?

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.

Cheers,

Rail

Don't forget the SharedResourcePointer class - it's very good for this kind of thing!

ah, ok, I got to give a look at that class yes!

also I just saw the "static Logger* currentLogger;" 

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

Yeah, it's not really for things like the logger. More for your own shared classes.

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 :slight_smile:

Cheers,

Rail

Thanks Jules

I went ahead and created a cleanup thread class last night… But I’ll check it out.

Cheers,

Rail

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.

Cheers,

Rail

Okay, I created a class CLogCounter:

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:

DBG ("Log Count: " + String (m_pLogCounter->addLog()));

In the destructor

    Logger::setCurrentLogger (nullptr);
    
    m_pLogCounter->removeLog();

If you wanted to have a shared instance of FileLogger you could call

Logger::setCurrentLogger (nullptr);

in the destructor if removeLog() returns zero.

Cheers,

Rail

good. You should probably use the plug type (AU/VST/...) for the naming also, just in case a user loads your plug as AU and VST in the same session.

I include that inside the log using

const String    getWrapperTypeString (int iType)
{
    switch (iType)
        {
            case AudioProcessor::WrapperType::wrapperType_Undefined:    return "Undefined";
            
            case AudioProcessor::WrapperType::wrapperType_VST:          return "VST";
            
            case AudioProcessor::WrapperType::wrapperType_VST3:         return "VST3";
            
            case AudioProcessor::WrapperType::wrapperType_AudioUnit:    return "Audio Unit";
            
            case AudioProcessor::WrapperType::wrapperType_RTAS:         return "RTAS";
            
            case AudioProcessor::WrapperType::wrapperType_AAX:          return "AAX";
        
            case AudioProcessor::WrapperType::wrapperType_Standalone:   return "Standalone";
        }
    
    return "Unknown";
}

Rail

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...

 

Thanks,

 

Rail

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.