Add more debug logging, allow file logging to be enabled by config