11import express from 'express' ;
22import type { Request , Response } from 'express' ;
33import PinoHttp from 'pino-http' ;
4- import PinoPretty from 'pino-pretty' ;
54import type { Promisable } from 'type-fest' ;
65
76import { config } from '@/config' ;
87import type { RenderFunction } from '@/entry-server' ;
8+ import { logger } from '@/logger' ;
99import { apiKeyMiddleware } from '@/middleware/api-key.middleware' ;
1010import { errorHandlerMiddleware } from '@/middleware/error-handler.middleware' ;
1111import type { RootProps } from '@/Root' ;
@@ -31,10 +31,8 @@ export abstract class BaseServer {
3131 } catch ( err ) {
3232 if ( err instanceof Error ) {
3333 this . fixStacktrace ?.( err ) ;
34- console . error ( err . stack ) ;
35- } else {
36- console . error ( err ) ;
3734 }
35+ logger . error ( err ) ;
3836 res . status ( 500 ) . json ( { message : 'Internal Server Error' , statusCode : 500 } ) ;
3937 }
4038 } ) ;
@@ -47,25 +45,21 @@ export abstract class BaseServer {
4745 } )
4846 ) ;
4947 this . app . use (
50- PinoHttp (
51- {
52- customLogLevel : ( _ , res ) => {
53- return res . statusCode >= 500 ? 'error' : 'info' ;
54- } ,
55- serializers : {
56- req : ( req : Request ) => {
57- return `${ req . method } ${ req . url } ` ;
58- } ,
59- res : ( res : Response ) => {
60- return res . statusCode ;
61- }
48+ PinoHttp ( {
49+ customLogLevel : ( _ , res ) => {
50+ return res . statusCode >= 500 ? 'error' : 'info' ;
51+ } ,
52+ logger,
53+ serializers : {
54+ req : ( req : Request ) => {
55+ return `${ req . method } ${ req . url } ` ;
6256 } ,
63- wrapSerializers : false
57+ res : ( res : Response ) => {
58+ return res . statusCode ;
59+ }
6460 } ,
65- PinoPretty ( {
66- colorize : true
67- } )
68- )
61+ wrapSerializers : false
62+ } )
6963 ) ;
7064 this . app . use ( '/api' , apiKeyMiddleware , apiRouter ) ;
7165 this . app . use ( '/' , this . rootLoader , rootRouter ) ;
@@ -76,8 +70,7 @@ export abstract class BaseServer {
7670
7771 listen ( port = config . port ) {
7872 return this . app . listen ( port , ( ) => {
79- // eslint-disable-next-line no-console
80- console . log ( `Server started at http://localhost:${ port } ` ) ;
73+ logger . info ( `Server started at http://localhost:${ port } ` ) ;
8174 } ) ;
8275 }
8376
0 commit comments