Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/request logs #140

Merged
merged 10 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zp-relayer/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const config = {
.map(s => parseInt(s, 10)),
requireTraceId: process.env.RELAYER_REQUIRE_TRACE_ID === 'true',
requireHTTPS: process.env.RELAYER_REQUIRE_HTTPS === 'true',
logIgnoreRoutes: (process.env.RELAYER_LOG_IGNORE_ROUTES || '').split(' ').filter(r => r.length > 0),
lok52 marked this conversation as resolved.
Show resolved Hide resolved
screenerUrl: process.env.RELAYER_SCREENER_URL || null,
screenerToken: process.env.RELAYER_SCREENER_TOKEN || null,
}
Expand Down
5 changes: 3 additions & 2 deletions zp-relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import './env'
import express from 'express'
import router from './router'
import { logger } from './services/appLogger'
import { createLoggerMiddleware } from './services/loggerMiddleware'
import { createConsoleLoggerMiddleware, createPersistentLoggerMiddleware } from './services/loggerMiddleware'
import config from './config'
import { init } from './init'

const app = express()

app.use(createLoggerMiddleware('zp.log'))
app.use(createPersistentLoggerMiddleware('zp.log'))
lok52 marked this conversation as resolved.
Show resolved Hide resolved
app.use(createConsoleLoggerMiddleware())

app.use(router)

Expand Down
30 changes: 26 additions & 4 deletions zp-relayer/services/loggerMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import winston from 'winston'
import { format, transports } from 'winston'
import expressWinston from 'express-winston'
import config from '@/config'
import { logger } from './appLogger'

export function createLoggerMiddleware(filename: string = 'zp.log') {
export function createPersistentLoggerMiddleware(filename: string = 'zp.log') {
return expressWinston.logger({
transports: [new winston.transports.File({ filename })],
format: winston.format.combine(winston.format.json()),
transports: [new transports.File({ filename })],
format: format.combine(format.json()),
})
}

export function createConsoleLoggerMiddleware() {
return expressWinston.logger({
winstonInstance: logger,
level: 'debug',
ignoredRoutes: config.logIgnoreRoutes,
headerBlacklist: [
'accept',
lok52 marked this conversation as resolved.
Show resolved Hide resolved
'accept-language',
'accept-encoding',
'connection',
'content-length',
'content-type',
'postman-token',
'referer',
'upgrade-insecure-requests',
],
requestWhitelist: ['headers', 'httpVersion'],
})
}