Page 1 of 1

Passing LogManager to another class

Posted: Mon Jul 04, 2016 10:32 am
by baffo32
I am designing a box plugin and would like some functionality to be separated out into another class.

However, I can't seem to write to the LogManager in this other class.

I find that if I pass the logmanager to the class constructor in the box plugin's initialize() function, the logmanager held by the class becomes invalid in process() -- apparently it is destroyed and recreated inbetween these two functions somehow.

Is there a proper way to access logging in another class used by a box plugin?

Re: Passing LogManager to another class

Posted: Mon Jul 04, 2016 12:55 pm
by jtlindgren
Hi Baffo, indeed that is an old design choice that the pointers are invalidated between the process() calls. A working solution is to pass the LogManager to the class each time during process() and pull the logmanager from that. Since its a pointer or a ref, there's not much overhead. Unfortunately this design means that you cannot print to the logmanager from a thread or when the scheduler is not in the scope of executing the box. To get around this, you can buffer the log messages and then send them out during either process() or processClock().

Ps. I imagine the design was due to an expectation that the boxes might migrate from one memory address space to another during runtime (like from a network computer to another)... hasn't happened so far.

Hope this helps,
Jussi

Re: Passing LogManager to another class

Posted: Sat Jul 09, 2016 3:31 pm
by baffo32
Thanks, this is the solution I am implementing now.