import config from './config.js';
import { Logger, ISettingsParam } from 'tslog';

// You can ignore every log message from being processed until a certain severity. Default severities are:
// 0: silly, 1: trace, 2: debug, 3: info, 4: warn, 5: error, 6: fatal

function loggerConfig(name: string): ISettingsParam<unknown> {
	return {
		type: 'pretty', // pretty, json, hidden
		name: name,
		hideLogPositionForProduction: true,
		prettyLogTemplate: '{{dateIsoStr}} {{logLevelName}} {{nameWithDelimiterPrefix}} ',
		minLevel: config.global.devmode ? 0 : 3 // Only display info, warn, error, fatal in production mode
	};
}

type log = {
	core: Logger<unknown>;
	db: Logger<unknown>;
	web: Logger<unknown>;
	auth: Logger<unknown>;
	api?: Logger<unknown>;
	frontend?: Logger<unknown>;
};

// FIXME: any type
let log: log = {
	core: new Logger(loggerConfig('Core')),
	db: new Logger(loggerConfig('DB')),
	web: new Logger(loggerConfig('Web')),
	auth: new Logger(loggerConfig('Auth'))
	//	helper: new Logger(loggerConfig("HELPER")),
};

log['api'] = log.web.getSubLogger({ name: 'API' });
log['frontend'] = log.web.getSubLogger({ name: 'Frontend' });

// log.core.silly("Hello from core");
// log.api.trace("Hello from api");
// log.frontend.trace("Hello from frontend");
// log.core.debug("Hello from core");
// log.core.info("Hello from core");
// log.core.warn("Hello from core");
// log.core.error("Hello from core");
// log.db.silly("Hello from db");
// log.db.trace("Hello from db");
// log.web.debug("Hello from db");
// log.auth.info("Hello from db");
// log.helper.warn("Hello from db");
// log.db.error("Hello from db");
// log.core.fatal(new Error("I am a pretty Error with a stacktrace."));

export default log;
