mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-03-12 10:30:21 +01:00
chore: improve logging
This commit is contained in:
parent
e092ece430
commit
aad9c79391
3 changed files with 10 additions and 2 deletions
1
.env
1
.env
|
@ -10,6 +10,7 @@
|
||||||
# Server Configs
|
# Server Configs
|
||||||
# -----------
|
# -----------
|
||||||
# LOG_LEVEL='info'
|
# LOG_LEVEL='info'
|
||||||
|
# LOG_JSON=true
|
||||||
# TOR_PROXY_SERVER=socks://127.0.0.1:9050
|
# TOR_PROXY_SERVER=socks://127.0.0.1:9050
|
||||||
# DISABLE_TWOFA=true
|
# DISABLE_TWOFA=true
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,13 @@ import { ApiModule } from './modules/api/api.module';
|
||||||
import { getAuthToken } from './utils/request';
|
import { getAuthToken } from './utils/request';
|
||||||
import { FetchModule } from './modules/fetch/fetch.module';
|
import { FetchModule } from './modules/fetch/fetch.module';
|
||||||
import { appConstants } from './utils/appConstants';
|
import { appConstants } from './utils/appConstants';
|
||||||
|
import { transports, format } from 'winston';
|
||||||
import configuration from './config/configuration';
|
import configuration from './config/configuration';
|
||||||
import winston from 'winston';
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import cookie from 'cookie';
|
import cookie from 'cookie';
|
||||||
|
|
||||||
|
const { combine, timestamp, prettyPrint, json } = format;
|
||||||
|
|
||||||
export type ContextType = {
|
export type ContextType = {
|
||||||
req: any;
|
req: any;
|
||||||
res: any;
|
res: any;
|
||||||
|
@ -95,7 +97,10 @@ export type JwtObjectType = {
|
||||||
inject: [ConfigService],
|
inject: [ConfigService],
|
||||||
useFactory: (config: ConfigService) => ({
|
useFactory: (config: ConfigService) => ({
|
||||||
level: config.get('logLevel'),
|
level: config.get('logLevel'),
|
||||||
transports: [new winston.transports.Console()],
|
transports: [new transports.Console()],
|
||||||
|
format: config.get('logJson')
|
||||||
|
? combine(timestamp(), json())
|
||||||
|
: combine(timestamp(), prettyPrint()),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
@ -26,6 +26,7 @@ export type YamlEnvs = {
|
||||||
type ConfigType = {
|
type ConfigType = {
|
||||||
basePath: string;
|
basePath: string;
|
||||||
isProduction: boolean;
|
isProduction: boolean;
|
||||||
|
logJson: boolean;
|
||||||
playground: boolean;
|
playground: boolean;
|
||||||
logLevel: string;
|
logLevel: string;
|
||||||
jwtSecret: string;
|
jwtSecret: string;
|
||||||
|
@ -76,6 +77,7 @@ export default (): ConfigType => {
|
||||||
|
|
||||||
const config: ConfigType = {
|
const config: ConfigType = {
|
||||||
isProduction,
|
isProduction,
|
||||||
|
logJson: process.env.LOG_JSON === 'true',
|
||||||
masterPasswordOverride: process.env.MASTER_PASSWORD_OVERRIDE || '',
|
masterPasswordOverride: process.env.MASTER_PASSWORD_OVERRIDE || '',
|
||||||
disable2FA: process.env.DISABLE_TWOFA === 'true',
|
disable2FA: process.env.DISABLE_TWOFA === 'true',
|
||||||
basePath: process.env.BASE_PATH || '',
|
basePath: process.env.BASE_PATH || '',
|
||||||
|
|
Loading…
Add table
Reference in a new issue