-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve logging (quite a bit) (#73)
* Improve logging * Bump package ver. Improve README slightly. * Package versions, vuln fixes * Some minor fixes
- Loading branch information
1 parent
36c46a7
commit 56a4567
Showing
18 changed files
with
689 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,58 @@ | ||
const pino = require('pino'); | ||
const createServer = require('./server'); | ||
const Database = require('./db'); | ||
const config = require('./config/config'); | ||
const log = require('./lib/log'); | ||
const { version } = require('./package.json'); | ||
|
||
// ///////////////////////////////////////////////////////////////////////////// | ||
// Config | ||
// ///////////////////////////////////////////////////////////////////////////// | ||
|
||
const logger = pino({ | ||
serializers: { | ||
// return the body for any HTTPResponseError types we receive from finance-portal-lib | ||
err: pino.stdSerializers.wrapErrorSerializer((e) => { | ||
if (e.type !== 'HTTPResponseError') { | ||
return e; | ||
} | ||
return { | ||
...e, | ||
body: e.raw.getData().resp, | ||
request: e.raw.getData().request, | ||
}; | ||
}), | ||
}, | ||
}); | ||
|
||
// Log development/production status | ||
log('Running portal version ', version); | ||
log('Running in ', process.env.NODE_ENV); | ||
logger.child({ version, env: process.env.NODE_ENV }).info('Running portal backend service'); | ||
|
||
// Set up the db | ||
const db = new Database(config.db); | ||
|
||
// Warnings for certain environment var settings | ||
if (config.cors.reflectOrigin && process.env.NODE_ENV !== 'development') { | ||
log('WARNING: NODE_ENV != \'development\' and CORS origin being reflected in Access-Control-Allow-Origin header. ' | ||
logger.warn('WARNING: NODE_ENV != \'development\' and CORS origin being reflected in Access-Control-Allow-Origin header. ' | ||
+ 'Changing CORS_ACCESS_CONTROL_REFLECT_ORIGIN to false is important for preventing CSRF.'); | ||
} | ||
if (config.auth.bypass) { | ||
log('WARNING: auth bypass enabled- all login requests will be approved'); | ||
logger.warn('WARNING: auth bypass enabled- all login requests will be approved'); | ||
} | ||
|
||
// ///////////////////////////////////////////////////////////////////////////// | ||
// Start app | ||
// ///////////////////////////////////////////////////////////////////////////// | ||
|
||
log('Config:', config); | ||
const server = createServer(config, db, log, Database); | ||
logger.child({ config }).info('Config:'); | ||
const server = createServer(config, db, logger, Database); | ||
const listener = server.listen(config.server.listenPort); | ||
|
||
const handle = async (signal) => { | ||
log(`Received signal ${signal}. Shutting down..`); | ||
logger.info(`Received signal ${signal}. Shutting down..`); | ||
listener.close(); | ||
process.exit(); | ||
}; | ||
process.on('SIGINT', handle); | ||
process.on('SIGTERM', handle); | ||
|
||
log(`Listening on port ${config.server.listenPort}`); | ||
logger.info(`Listening on port ${config.server.listenPort}`); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.