mirror of
https://github.com/status-im/codimd.git
synced 2025-01-12 07:54:33 +00:00
use winston.http to log morgan, and adjust development output
Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
8fb31bd018
commit
41f0e61049
@ -75,8 +75,9 @@ app.use(expressPrometheusMetricsMiddleware({
|
||||
}))
|
||||
|
||||
// logger
|
||||
app.use(morgan('combined', {
|
||||
stream: logger.stream
|
||||
const morganLogType = config.env === config.Environment.development ? 'dev' : 'combined'
|
||||
app.use(morgan(morganLogType, {
|
||||
stream: logger.morganLog,
|
||||
}))
|
||||
|
||||
// socket io
|
||||
@ -338,6 +339,7 @@ function handleTermSignals() {
|
||||
process.exit(1)
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
process.on('SIGINT', handleTermSignals)
|
||||
process.on('SIGTERM', handleTermSignals)
|
||||
process.on('SIGQUIT', handleTermSignals)
|
||||
|
@ -5,7 +5,7 @@ const defaultConfig = {
|
||||
urlPath: '',
|
||||
host: '0.0.0.0',
|
||||
port: 3000,
|
||||
loglevel: 'info',
|
||||
loglevel: 'http',
|
||||
urlAddPort: false,
|
||||
allowOrigin: ['localhost'],
|
||||
useSSL: false,
|
||||
|
@ -46,7 +46,7 @@ merge(config, require('./environment'))
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
merge(config, require('./dockerSecret'))
|
||||
|
||||
if (['debug', 'verbose', 'info', 'warn', 'error'].includes(config.loglevel)) {
|
||||
if (['debug', 'verbose', 'http', 'info', 'warn', 'error'].includes(config.loglevel)) {
|
||||
logger.setLevel(config.loglevel)
|
||||
} else {
|
||||
logger.error('Selected loglevel %s doesn\'t exist, using default level \'debug\'. Available options: debug, verbose, info, warn, error', config.loglevel)
|
||||
@ -213,7 +213,7 @@ config.tmpPath = path.resolve(appRootPath, config.tmpPath)
|
||||
config.defaultNotePath = path.resolve(appRootPath, config.defaultNotePath)
|
||||
config.docsPath = path.resolve(appRootPath, config.docsPath)
|
||||
config.uploadsPath = path.resolve(appRootPath, config.uploadsPath)
|
||||
|
||||
config.env = env
|
||||
// make config readonly
|
||||
config = deepFreeze(config) as any
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
import {createLogger, format, transports, Logger} from "winston";
|
||||
|
||||
|
||||
type CodiMDLogger = Logger & {
|
||||
stream: any
|
||||
morganLog?: {
|
||||
write: (message: string) => void
|
||||
}
|
||||
setLevel?: (string) => void
|
||||
}
|
||||
|
||||
@ -23,7 +26,6 @@ if (process.env.NODE_ENV === 'development' || !process.env.NODE_ENV) {
|
||||
}
|
||||
|
||||
const logger: CodiMDLogger = createLogger({
|
||||
level: 'debug',
|
||||
format: defaultFormatter,
|
||||
transports: [
|
||||
new transports.Console({
|
||||
@ -33,9 +35,10 @@ const logger: CodiMDLogger = createLogger({
|
||||
exitOnError: false
|
||||
})
|
||||
|
||||
logger.stream = {
|
||||
write: function (message, encoding) {
|
||||
logger.info(message)
|
||||
// for morgan used
|
||||
logger.morganLog = {
|
||||
write: buffer => {
|
||||
logger.http(buffer.trim())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user