Excute function vs Custom event function c++

Hi

I created some toggle to control function
and placed it inside the execute function.

[code]//Logger retrive state and Control On\Off.

inputs->enablePar("Logger", 1);
auto Logger = inputs->getParInt("Logger");
std::cout << "Logger is: " << Logger << std::endl;

if (Logger) 
{
	AttachToLogger();
}
else 
{ 
	DetachFromLogger();
}

///////////End of Logger control//////////////////////////[/code]

I noticed there are a lot of code running inside the execute function and it could
result in very not efficient code as we dont need to execute some of the code in each frame.

What can be a good practice to run functions per event ?
I know it can be general c++ \ coding question - any answer I can learn from
will be great -
ultimately I want to write code in a closer manner to how you guys in derivative do.
It can help communicate better in the future.

thank you,

Barak