Skip to content

Commit

Permalink
fix(general): set config from logging. Fixes MEMB-547
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Sep 1, 2019
1 parent 1b1e394 commit cb97997
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions config/index.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const config = {
url: 'http://oms-mailer',
port: 4000
},
logger: {
silent: false,
level: process.env.LOGLEVEL || 'debug'
},
bugsnagKey: process.env.BUGSNAG_KEY || ''
},
development: {
Expand All @@ -30,6 +34,9 @@ const config = {
database: 'discounts-testing',
password: process.env.PG_PASSWORD || 'postgres',
},
logger: {
silent: (typeof process.env.ENABLE_LOGGING !== 'undefined') ? (!process.env.ENABLE_LOGGING) : true
},
bugsnagKey: 'CHANGEME'
}
};
Expand Down
8 changes: 4 additions & 4 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const winston = require('winston');

// Setting logLevel to warn in case of testing, to display only errors and warnings.
const logLevel = process.env.NODE_ENV === 'test' ? 'warn' : 'debug';
const config = require('../config');

const logger = winston.createLogger({
level: logLevel,
level: config.logger.level,
silent: config.logger.silent,
format: winston.format.json(),
transports: [
new winston.transports.Console({
Expand All @@ -13,7 +13,7 @@ const logger = winston.createLogger({
winston.format.timestamp(),
winston.format.align(),
winston.format.splat(),
winston.format.printf((info) => `${info.timestamp} [${info.level}]: ${info.message}`),
winston.format.printf(info => `${info.timestamp} [${info.level}]: ${info.message}`),
)
})
]
Expand Down
1 change: 1 addition & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ server.use(middlewares.errorHandler);
let app;
async function startServer() {
return new Promise((res, rej) => {
log.info('Starting server with the following config: %o', config);
const localApp = server.listen(config.port, async () => {
app = localApp;
log.info('Up and running, listening on http://localhost:%d', config.port);
Expand Down

0 comments on commit cb97997

Please sign in to comment.