main code of writing log