Skip to content

Commit

Permalink
feat: sql logging hashes queries
Browse files Browse the repository at this point in the history
  • Loading branch information
wwills2 committed Sep 19, 2024
1 parent 70a06ea commit 6d95bab
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@ import { getConfig } from '../utils/config-loader';
import { getDataModelVersion } from '../utils/helpers';
import { getChiaRoot } from '../utils/chia-root.js';
import { logger } from './logger.js';
import { createHash } from 'crypto';

const chiaRoot = getChiaRoot();
const persistanceFolder = `${chiaRoot}/cadt/${getDataModelVersion()}`;

const localQueryLogger = (query) => {
const queryString = query.split(/:\s(.+)/)[1];
const queryHash = createHash('md5').update(queryString).digest('hex');
logger.debug(`SQLite Sequelize [query hash: ${queryHash}]\n\t${query}`);
};

const mirrorQueryLogger = (query) => {
const queryString = query.split(/:\s(.+)/)[1];
const queryHash = createHash('md5').update(queryString).digest('hex');
logger.debug(`Mirror DB Sequelize [query hash: ${queryHash}]\n\t${query}`);
};

const appLogLevel = getConfig().APP.LOG_LEVEL;
const localLogging =
appLogLevel === 'silly' || appLogLevel === 'debug'
? (query) => logger.debug(`SQLite Sequelize ${query}`)
: false;
appLogLevel === 'silly' || appLogLevel === 'debug' ? localQueryLogger : false;
const mirrorLogging =
appLogLevel === 'silly' || appLogLevel === 'debug'
? (query) => logger.debug(`Mirror DB Sequelize ${query}`)
? mirrorQueryLogger
: false;

export default {
Expand Down

0 comments on commit 6d95bab

Please sign in to comment.