84cb74e8b3
* each log line is a json object * structured logging allows logs to be ingested by machines and the logs to be indexed and queried addresses #1105 * structured logging allows arbitrary properties to be appended to each log line, and ingestion of logs to remain robust * Structured logging provided by `pino` library * Add `express-pino-logger` dependency * Remove `debug`, `morgan`, and `morgan-debug` and replace with structured logging * `console.log` & `console.error` replaced with structured logging in backend * Remove `DEBUG` environment variable and replace with `LOG_LEVEL` - Note that there is a test which reads from a logged line on `stdout`. This is not robust, it would be better to use the childProcess.pid to look up the port number. * Log errors at points we explicitly send error to Sentry * Amend indentation of a couple of log messages to align indentation with others
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/* istanbul ignore file */
|
|
/**
|
|
* Bootstrap module that should be imported at the very top of each entry point module
|
|
*/
|
|
|
|
// Conditionally change appRoot and packageRoot according to whether we're running from /dist/ or not (ts-node)
|
|
const path = require('path')
|
|
const isTsNode = !!process[Symbol.for('ts-node.register.instance')]
|
|
const appRoot = __dirname
|
|
const packageRoot = isTsNode ? appRoot : path.resolve(__dirname, '../')
|
|
|
|
// Initializing module aliases for absolute import paths
|
|
const moduleAlias = require('module-alias')
|
|
moduleAlias.addAliases({
|
|
'@': appRoot,
|
|
'#': packageRoot
|
|
})
|
|
|
|
// Initializing env vars
|
|
const dotenv = require('dotenv')
|
|
const {
|
|
isTestEnv,
|
|
isApolloMonitoringEnabled,
|
|
getApolloServerVersion,
|
|
getServerVersion
|
|
} = require('./modules/shared/helpers/envHelper')
|
|
const { logger } = require('@/logging/logging')
|
|
|
|
if (isApolloMonitoringEnabled() && !getApolloServerVersion()) {
|
|
process.env.APOLLO_SERVER_USER_VERSION = getServerVersion()
|
|
}
|
|
|
|
// If running in test env, load .env.test first
|
|
// (appRoot necessary, cause env files aren't loaded through require() calls)
|
|
if (isTestEnv()) {
|
|
const { error } = dotenv.config({ path: `${packageRoot}/.env.test` })
|
|
if (error) {
|
|
const e = new Error(
|
|
'Attempting to run tests without an .env.test file properly set up! Check readme!'
|
|
)
|
|
logger.error(e)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
dotenv.config({ path: `${packageRoot}/.env` })
|
|
|
|
module.exports = {
|
|
appRoot,
|
|
packageRoot
|
|
}
|