Yes, but its not really pretty.
You can do exec 2> error.log to send stderr to a file
The problem is that you now have to clean it up and restore stderr, so at the bottom of the function you have to do exec 2>&1, which makes stderr go back to the terminal again.
function XX()
{
exec 2> error.log
foo bar
exec 2>&1
}
The exec 2>&1 doesnt hurt to leave in, so you can just comment and uncomment the first exec.
Alternatively you could make the whole function execute in a subshell so that redirections are cleaned up automatically (the parenthesis in the below example start a subshell).
function XX()
{ (
exec 2> error.log
foo bar
) }
Lastly, you could just create an alias definition that you can comment and uncomment easily, and just put it right before the function declaration.
alias XX='XX 2> error.log'
function XX()
{
foo bar
}
command | XXinstead ofcommand 2>/dev/null?