Add option to enable MikroORM database debug logging

This commit is contained in:
William Oldham 2023-11-18 19:21:02 +00:00
parent 6f48b62275
commit 8e10eb7d59
3 changed files with 14 additions and 3 deletions

View File

@ -41,6 +41,10 @@ export const configSchema = z.object({
// will always keep the database schema in sync with the connected database
// it is extremely destructive, do not use it EVER in production
syncSchema: z.coerce.boolean().default(false),
// Enable debug logging for MikroORM - Outputs queries and entity management logs
// Do NOT use in production, leaks all sensitive data
debugLogging: z.coerce.boolean().default(false),
}),
crypto: z.object({
// session secret. used for signing session tokens

View File

@ -14,8 +14,10 @@ export function getORM() {
export async function setupMikroORM() {
log.info(`Connecting to postgres`, { evt: 'connecting' });
const mikro = await createORM(conf.postgres.connection, (msg) =>
log.info(msg),
const mikro = await createORM(
conf.postgres.connection,
conf.postgres.debugLogging,
(msg) => log.info(msg),
);
if (conf.postgres.syncSchema) {

View File

@ -16,9 +16,14 @@ export function makeOrmConfig(url: string): Options<PostgreSqlDriver> {
};
}
export async function createORM(url: string, log: (msg: string) => void) {
export async function createORM(
url: string,
debug: boolean,
log: (msg: string) => void,
) {
return await MikroORM.init<PostgreSqlDriver>({
...makeOrmConfig(url),
logger: log,
debug,
});
}