extended logging code

Made it more flexible