added flag to turn on or off logging (defaults to false)