Closed morbeo closed 7 years ago
By declaring them this way, they do not pollute the global variables. Sometimes b3bp may be sourced rather than called directly, so it can be nice to encapsulate this data within a function and provide some data hiding.
How are you debugging? Are you using set -o xtrace
(AKA set -x
) or are you sprinkling info
calls etc throughout your code? Have you confirmed that it is indeed the setting of these variables that is causing the slowdown?
@morbeo if you are willing to share a profile of your script using https://github.com/F-Hauri/bashProfiler I'd be curious to see how bad it is.
The colors do look kind of global. I mean, are you going to change them? :)
There is no slowdown at all, I am sorry if I implied there is.
Yes, it is about xtrace. I am just running the example LOG_LEVEL=7 ./boiler.sh -f /tmp/x -d
Basically any output is from that function includes the color variables declaration and that annoys me a lot :) I guess I will rewrite it to my liking.
I noticed that the logging colors are defined in the __b3bp_log function and that they are set every time the function is called. Highly unlikely it have a noticeable impact on performance, but debugging stuff is terrible with the overhead. Is it necessary to redeclare them on each call? Of course I can move them outside myself, but if there is a specific reasoning for this structure I would like to hear it.