Log fuction and directory checking function