For logging in Matlab, I actually use an M-code wrapper layer that sits
on top of log4j + SLF4J and presents an M-code interface for it (with
short-circuiting for performance) and a little configurator GUI. That
way you get all the features of log4j/SLF4J, and any Java code or
libraries you use in your application can go through the same logging
mechanism so it can be configured at a single point.
https://github.com/apjanke/SLF4M
(Background - I've used logging layers like this in enterprise Matlab
systems, so I'm confident it's a decent approach.)
It wouldn't be too hard to port this to Octave. Or if Java dot-reference
support were added to Octave (https://savannah.gnu.org/bugs/?48428), it
should just work as is.
There are a couple other logging packages on MathWorks File Exchange
that use pure M-code, and might work as is in Octave, too.
https://www.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=logging
I wouldn't worry about performance optimization too much; the main thing
to worry about is keeping your logging calls out of tight loops.
Cheers,
Andrew