chore: improve logging

This commit is contained in:
apotdevin 2021-12-20 10:40:44 -05:00
parent e092ece430
commit aad9c79391
No known key found for this signature in database
GPG key ID: 4403F1DFBE779457
3 changed files with 10 additions and 2 deletions

1
.env
View file

@ -10,6 +10,7 @@
# Server Configs
# -----------
# LOG_LEVEL='info'
# LOG_JSON=true
# TOR_PROXY_SERVER=socks://127.0.0.1:9050
# DISABLE_TWOFA=true

View file

@ -11,11 +11,13 @@ import { ApiModule } from './modules/api/api.module';
import { getAuthToken } from './utils/request';
import { FetchModule } from './modules/fetch/fetch.module';
import { appConstants } from './utils/appConstants';
import { transports, format } from 'winston';
import configuration from './config/configuration';
import winston from 'winston';
import jwt from 'jsonwebtoken';
import cookie from 'cookie';
const { combine, timestamp, prettyPrint, json } = format;
export type ContextType = {
req: any;
res: any;
@ -95,7 +97,10 @@ export type JwtObjectType = {
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
level: config.get('logLevel'),
transports: [new winston.transports.Console()],
transports: [new transports.Console()],
format: config.get('logJson')
? combine(timestamp(), json())
: combine(timestamp(), prettyPrint()),
}),
}),
],

View file

@ -26,6 +26,7 @@ export type YamlEnvs = {
type ConfigType = {
basePath: string;
isProduction: boolean;
logJson: boolean;
playground: boolean;
logLevel: string;
jwtSecret: string;
@ -76,6 +77,7 @@ export default (): ConfigType => {
const config: ConfigType = {
isProduction,
logJson: process.env.LOG_JSON === 'true',
masterPasswordOverride: process.env.MASTER_PASSWORD_OVERRIDE || '',
disable2FA: process.env.DISABLE_TWOFA === 'true',
basePath: process.env.BASE_PATH || '',