Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
removed inconsistent request logging
Browse files Browse the repository at this point in the history
  • Loading branch information
a-thaler committed Nov 11, 2020
1 parent 69e66f2 commit 42db15e
Show file tree
Hide file tree
Showing 4 changed files with 538 additions and 64 deletions.
41 changes: 0 additions & 41 deletions modules/api-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions modules/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"express": "^4.17.1",
"express-winston": "^4.0.5",
"json-schema-ref-parser": "^9.0.6",
"morgan": "^1.10.0",
"openapi-sampler": "^1.0.0-beta.18",
"swagger-ui-dist": "^3.36.2",
"winston": "^3.3.3"
Expand All @@ -34,7 +33,6 @@
"@types/express-winston": "^4.0.0",
"@types/json-schema": "^7.0.6",
"@types/mocha": "^8.0.3",
"@types/morgan": "^1.9.2",
"@types/node": "^14.14.7",
"@types/supertest": "^2.0.10",
"@types/yaml": "^1.9.7",
Expand Down
27 changes: 6 additions & 21 deletions modules/api-server/src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as events from "./routes/events";
import * as remoteApis from "./routes/remoteApis";
import * as localApis from "./routes/localApis";
import * as config from "@varkes/configuration"
import * as morgan from "morgan"

const VARKES_LOGO = path.resolve(__dirname, 'resources/logo.svg')
const LOGO_URL = "/logo";
Expand All @@ -31,8 +30,12 @@ async function init(config: config.Config) {
app.use(bodyParser.json())
app.use(cors())
app.options('*', cors())
app.use(expressWinston.logger(LOGGER))
app.use(morganLogger())

app.use(expressWinston.logger({
winstonInstance: LOGGER,
msg: "{{req.method}} {{req.url}}, status: {{res.statusCode}}{{process.env.DEBUG && process.env.NODE_ENV!='production' ?', headers: '+JSON.stringify(req.headers):''}}",
expressFormat: false
}))
app.use(REMOTE_APIS_URL, remoteApis.router())
app.use(LOCAL_APIS_URL, localApis.router(config))
app.use(CONNECTION, connector.router())
Expand All @@ -42,7 +45,6 @@ async function init(config: config.Config) {
app.use("/swagger-ui", express.static(pathToSwaggerUI))

app.get("/info", function (req, res) {

let info = {
appName: config.name,
links: {
Expand Down Expand Up @@ -71,21 +73,4 @@ async function init(config: config.Config) {
return app;
}

function morganLogger():any {
morgan.token('header', (req: any) => {
if (req.rawHeaders && Object.keys(req.rawHeaders).length != 0)
return req.rawHeaders;
else
return "-";
});
morgan.token('body', function (req: any) {
if (req.body && Object.keys(req.body).length != 0)
return JSON.stringify(req.body);
else
return "-";
});
let logging_string = '[:date[clf]] ":method :url, Status: :status"\n Headers:\n :header\n Body:\n :body'
return morgan(logging_string)
}

export { init }
Loading

0 comments on commit 42db15e

Please sign in to comment.