Improve log handling

This commit is contained in:
syuilo 2020-03-28 18:28:21 +09:00
parent 614a1d74dd
commit 8e1b90ab43
3 changed files with 6 additions and 2 deletions

View file

@ -57,6 +57,7 @@ import { Antenna } from '../models/entities/antenna';
import { AntennaNote } from '../models/entities/antenna-note'; import { AntennaNote } from '../models/entities/antenna-note';
import { PromoNote } from '../models/entities/promo-note'; import { PromoNote } from '../models/entities/promo-note';
import { PromoRead } from '../models/entities/promo-read'; import { PromoRead } from '../models/entities/promo-read';
import { program } from '../argv';
const sqlLogger = dbLogger.createSubLogger('sql', 'white', false); const sqlLogger = dbLogger.createSubLogger('sql', 'white', false);
@ -149,7 +150,7 @@ export const entities = [
...charts as any ...charts as any
]; ];
export function initDb(justBorrow = false, sync = false, log = false, forceRecreate = false) { export function initDb(justBorrow = false, sync = false, forceRecreate = false) {
if (!forceRecreate) { if (!forceRecreate) {
try { try {
const conn = getConnection(); const conn = getConnection();
@ -157,6 +158,8 @@ export function initDb(justBorrow = false, sync = false, log = false, forceRecre
} catch (e) {} } catch (e) {}
} }
const log = program.verbose;
return createConnection({ return createConnection({
type: 'postgres', type: 'postgres',
host: config.db.host, host: config.db.host,

View file

@ -54,6 +54,7 @@ export default class Logger {
private log(level: Level, message: string, data?: Record<string, any> | null, important = false, subDomains: Domain[] = [], store = true): void { private log(level: Level, message: string, data?: Record<string, any> | null, important = false, subDomains: Domain[] = [], store = true): void {
if (program.quiet) return; if (program.quiet) return;
if (!this.store) store = false; if (!this.store) store = false;
if (level === 'debug') store = false;
if (this.parentLogger) { if (this.parentLogger) {
this.parentLogger.log(level, message, data, important, [this.domain].concat(subDomains), store); this.parentLogger.log(level, message, data, important, [this.domain].concat(subDomains), store);

View file

@ -63,7 +63,7 @@ describe('Chart', () => {
after(async(async () => { after(async(async () => {
await connection.close(); await connection.close();
await initDb(true, undefined, undefined, true); await initDb(true, undefined, true);
})); }));
beforeEach(done => { beforeEach(done => {