async function log( level, namespace, data, debug ) {
	if ( !data || LOG_LEVELS.indexOf( level ) < 1 ) {
		return Promise.resolve();
	}

	if ( debug ) {
		debug = LISTEN_TO_DEBUG
			? debug instanceof Function
				? debug()
				: debug
			: null;
	}

	const logMethod = level === LOG_LEVEL_ERROR
		? writeStdErr
		: writeStdOut;

	try {
		await logMethod( format( level, namespace, data, debug ) );
	} catch ( e ) {}

	if ( argv[ ARG_LOGFILE ] ) {
		try {
			if ( !logFilePath ) {
				await mkdirp( logdir );
				await clearfolder( logdir, maxAgeDays * 24 * 3600 * 1000 );

				logFilePath = join( logdir, logFileName );
			}
			await appendFile( logFilePath, formatFile( level, namespace, data, debug ) );
		} catch ( e ) {}
	}
}
@param {String} level
@param {String} namespace
@param {(Object|String|Error)} data
@param {(*|Function)?} debug
@returns {Promise}