To view the log of a function

I have a function like this

 
validate()
{
/* Inside this I will do some activites
}

How I can redirect this function to a log file , so that If I look into that log file I can understand ,is there any error happened inside the function or not

Well, what be the system (shell, language, ...)?

I am using shell scripting

Well, there's many a shell in them there hills. If it were bash, you could set -vx ; cf man bash:

Use redirection into a log file to be read/evaluated later.