Add debug output and ability to set log level