Conditional logging levels

Split out file writer to enable testing