Passing LogManager to another class

Making & changing box plugins and external apps
Post Reply
baffo32
Posts: 3
Joined: Sun Jul 03, 2016 1:07 pm

Passing LogManager to another class

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

jtlindgren
Posts: 778
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: Passing LogManager to another class

Post 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

baffo32
Posts: 3
Joined: Sun Jul 03, 2016 1:07 pm

Re: Passing LogManager to another class

Post by baffo32 »

Thanks, this is the solution I am implementing now.

Post Reply