constructor()

in apps-rendering/src/logger/server/index.ts [16:70]


	constructor() {
		let winstonConfig: winston.LoggerOptions;
		if (process.env.NODE_ENV === 'production') {
			winstonConfig = {
				level: 'info',
				defaultMeta: {
					app: App,
					stack: Stack,
					stage: Stage,
				},
				transports: [
					new DailyRotateFile({
						filename: `${App}.log`,
						dirname: `/var/log/${App}`,
						zippedArchive: true,
						maxSize: '50m',
						maxFiles: '7d',
						utc: true,
					}),
				],
				format: winston.format.json(),
			};
		} else {
			winstonConfig = {
				level: 'debug',
				silent: !!process.env.GITHUB_ACTIONS,
				defaultMeta: {
					app: App,
					stack: Stack,
					stage: Stage,
				},
				transports: [new winston.transports.Console()],
				format: winston.format.printf((logObject) => {
					const maybeTimestamp: unknown = logObject['@timestamp'];
					const maybeStackTrace: unknown = logObject['stack_trace'];
					const stackTrace =
						typeof maybeStackTrace === 'string'
							? `, ${maybeStackTrace}`
							: '';
					const timestamp =
						typeof maybeTimestamp === 'string'
							? maybeTimestamp
							: 'Unknown Timestamp';
					const message =
						typeof logObject.message === 'string'
							? logObject.message
							: '';

					return `${timestamp} [${logObject.level}] ${message}${stackTrace}`;
				}),
			};
		}

		this.underlyingLogger = winston.createLogger(winstonConfig);
	}