Skip to content
Snippets Groups Projects
Commit 58726c89 authored by Steve Reis's avatar Steve Reis
Browse files

Merge branch 'feat/logger-levels' into 'develop'

Add log levels

See merge request sibmip/gateway!65
parents 9fd3e5df 873d9fce
No related branches found
No related tags found
No related merge requests found
......@@ -2,15 +2,28 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import {
BadRequestException,
HttpException,
InternalServerErrorException,
LogLevel,
NotFoundException,
RequestTimeoutException,
UnauthorizedException,
} from '@nestjs/common';
import axios from 'axios';
export const LOG_LEVELS = [
['warn', 'error'],
['warn', 'error', 'log'],
['warn', 'error', 'log', 'verbose'],
['warn', 'error', 'log', 'verbose', 'debug'],
];
export const getLogLevels = (level: number): LogLevel[] => {
let internLevel = level - 1;
if (internLevel > LOG_LEVELS.length || internLevel < 0) internLevel = 0;
return LOG_LEVELS[internLevel] as LogLevel[];
};
export const errorAxiosHandler = (e: any) => {
if (!axios.isAxiosError(e)) throw new InternalServerErrorException(e);
......
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './main/app.module';
import * as cookieParser from 'cookie-parser';
import { getLogLevels } from './common/utils/shared.utils';
import { AppModule } from './main/app.module';
const CORS_URL = process.env.CORS_URL ?? process.env.ENGINE_BASE_URL;
const DEFAULT_LEVEL = process.env.NODE_ENV === 'production' ? 1 : 4;
const LOG_LEVEL = process.env.LOG_LEVEL
? parseInt(process.env.LOG_LEVEL)
: DEFAULT_LEVEL;
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
......@@ -15,6 +20,7 @@ async function bootstrap() {
CORS_URL,
],
},
logger: getLogLevels(LOG_LEVEL),
});
app.use(cookieParser());
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment