mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 17:25:16 -04:00
Switch to new buffered logger
NestJS 8 allows the logs to buffer on startup, so that all logs run through our custom logger. See also https://docs.nestjs.com/techniques/logger#dependency-injection Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
2a382d0fe6
commit
ab231e0f6e
2 changed files with 9 additions and 2 deletions
|
@ -4,7 +4,13 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Inject, Injectable, Optional, Scope } from '@nestjs/common';
|
import {
|
||||||
|
Inject,
|
||||||
|
Injectable,
|
||||||
|
LoggerService,
|
||||||
|
Optional,
|
||||||
|
Scope,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { isObject } from '@nestjs/common/utils/shared.utils';
|
import { isObject } from '@nestjs/common/utils/shared.utils';
|
||||||
import clc = require('cli-color');
|
import clc = require('cli-color');
|
||||||
import DateTimeFormatOptions = Intl.DateTimeFormatOptions;
|
import DateTimeFormatOptions = Intl.DateTimeFormatOptions;
|
||||||
|
@ -13,7 +19,7 @@ import { Loglevel } from '../config/loglevel.enum';
|
||||||
import { needToLog } from '../config/utils';
|
import { needToLog } from '../config/utils';
|
||||||
|
|
||||||
@Injectable({ scope: Scope.TRANSIENT })
|
@Injectable({ scope: Scope.TRANSIENT })
|
||||||
export class ConsoleLoggerService {
|
export class ConsoleLoggerService implements LoggerService {
|
||||||
private classContext: string | undefined;
|
private classContext: string | undefined;
|
||||||
private lastTimestamp: number;
|
private lastTimestamp: number;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { ConsoleLoggerService } from './logger/console-logger.service';
|
||||||
async function bootstrap(): Promise<void> {
|
async function bootstrap(): Promise<void> {
|
||||||
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
||||||
logger: ['error', 'warn', 'log'] as LogLevel[],
|
logger: ['error', 'warn', 'log'] as LogLevel[],
|
||||||
|
bufferLogs: true,
|
||||||
});
|
});
|
||||||
const logger = await app.resolve(ConsoleLoggerService);
|
const logger = await app.resolve(ConsoleLoggerService);
|
||||||
logger.log('Switching logger', 'AppBootstrap');
|
logger.log('Switching logger', 'AppBootstrap');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue