Skip to content

Commit

Permalink
Fix logger config
Browse files Browse the repository at this point in the history
- Use the same logger config as analytics-reporter
- Deprecate old deploy script
  • Loading branch information
levinmr committed Mar 6, 2024
1 parent 952b5a5 commit b00df0c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
16 changes: 0 additions & 16 deletions bin/deploy-ci.sh

This file was deleted.

3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ if (process.env.NEW_RELIC_APP_NAME) {

const app = require("./src/app");
const config = require("./src/config");
const logger = require("./src/logger").initialize();

app.listen(config.port, () => {
console.log(`Listening on ${config.port}`);
logger.info(`Listening on ${config.port}`);
});
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const app = express();
app.use(apiDataGovFilter);
app.use(router);
if (process.env.NODE_ENV != "test") {
app.use(logger);
app.use(logger.middleware());
}

const formatDateForDataPoint = (dataPoint) => {
Expand Down
30 changes: 24 additions & 6 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
const expressWinston = require("express-winston");
const winston = require("winston");
const config = require("./config");

const logger = expressWinston.logger({
transports: [new winston.transports.Console()],
expressFormat: true,
colorize: true,
});
const loggerConfig = () => {
return {
level: config.log_level,
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple(),
),
transports: [
new winston.transports.Console({
level: config.log_level,
}),
],
};
};

module.exports = logger;
const initialize = () => {
return winston.createLogger(loggerConfig());
};

const middleware = () => {
return expressWinston.logger(loggerConfig());
};

module.exports = { initialize, middleware };

0 comments on commit b00df0c

Please sign in to comment.