My program needs to write in
/var/log as well as
/usr/lib including all the sub-folders in these directories.
How do I give permission for my program to do it?
The only safe way of doing this would be to run your program as root. Any program that needs to write to system directories should be run as root anyway. A normal user has no business accessing those directories.
If your really, really want to make your system insecure you can look up SUID. Although, as explained here, you will have trouble setting SUID for scripts.
I really do not recommend this though. Seriously, just run your program as root. On a debian derived system (or any other that has sudo configured) do:
If sudo is not configured, do: