adding loglevel and optional logging
adding loglevel and optional logging