major overhaul of logging functions, provide cleanup upon exit, passing config as parameter