How to use the express-winston.errorLogger function in express-winston

To help you get started, we’ve selected a few express-winston examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / github-owners-bot / src / logging.js View on Github external
const colorize = process.env.NODE_ENV !== 'production';

// Logger to capture all requests and output them to the console.
const requestLogger = expressWinston.logger({
  transports: [
    new winston.transports.Console({
      json: false,
      colorize: colorize,
    }),
  ],
  expressFormat: true,
  meta: true,
});

// Logger to capture any top-level errors and output json diagnostic info.
const errorLogger = expressWinston.errorLogger({
  transports: [
    new winston.transports.Console({
      json: true,
      colorize: colorize,
    }),
  ],
});

export default {
  requestLogger,
  errorLogger,
  error: winston.error,
  warn: winston.warn,
  info: winston.info,
  log: winston.log,
  verbose: winston.verbose,
github MinionsDave / live-streaming-crawler / app.js View on Github external
});

// 开发环境中发送错误堆栈到前端并打印到控制台
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err,
    });
    console.error(err);
  });
}

// 生产环境中保留错误日志
app.use(expressWinston.errorLogger({
  transports: [
    new winston.transports.Console({
      json: true,
      colorize: true,
    }),
    new winston.transports.File({
      filename: 'logs/error.log',
    }),
  ],
}));

// 错误时发送邮件提醒
app.use(function(err, req, res, next) {
  sendErrMailFn(err);
  next(err);
});
github SoftwareEngineeringDaily / software-engineering-daily-api / config / express.js View on Github external
} else if (!(err instanceof APIError)) {
    const apiError = new APIError(err.message, err.status, err.isPublic);
    return next(apiError);
  }
  return next(err);
});

// catch 404 and forward to error handler
app.use((req, res, next) => {
  const err = new APIError('API not found', httpStatus.NOT_FOUND);
  return next(err);
});

// log error in winston transports except when executing test suite
if (config.env !== 'test') {
  app.use(expressWinston.errorLogger({
    winstonInstance
  }));
}

// error handler, send stacktrace only during development
app.use((
  err,
  req,
  res,
  next // eslint-disable-line no-unused-vars
) =>
  res.status(err.status).json({
    message: err.isPublic ? err.message : httpStatus[err.status],
    stack: config.env === 'development' ? err.stack : {}
  }));
github vpdb / server / src / express.js View on Github external
// set APP_SETTINGS=c:\dev\vpdb-backend\src\config\settings-sauce.js
	// set NODE_ENV=test
	// set WEBAPP=vpdb-website/dist
	if (runningTest) {
		if (staticWebApp && fs.existsSync(staticWebApp)) {
			logger.info('[express] Serving static webapp at %s...', staticWebApp);
			app.use(express.static(staticWebApp));
			app.use('/*', (req, res) => res.sendfile(staticWebApp + '/index.html'));

		} else if (staticWebApp) {
			logger.warn('[express] Ignoring WEBAPP parameter "%", "%" does not exist.', process.env.WEBAPP, staticWebApp);
		}
	}

	// error logger comes at the very last
	app.use(expressWinston.errorLogger({
		transports: [
			new logger.transports.Console({ json: false, colorize: true })
		]
	}));

	/* istanbul ignore if  */
	// production only
	if (!runningDev) {
		http.globalAgent.maxSockets = 500; // set this high, if you use httpClient or request anywhere (defaults to 5)
	}

	// development only
	if (runningDev) {
		app.use(expressErrorhandler());
		app.locals.pretty = false;
	}
github eclipse / repairnator / website / repairnator-mongo-rest-api / config / express.js View on Github external
} else if (!(err instanceof APIError)) {
    const apiError = new APIError(err.message, err.status, err.isPublic);
    return next(apiError);
  }
  return next(err);
});

// catch 404 and forward to error handler
app.use((req, res, next) => {
  const err = new APIError('API not found', httpStatus.NOT_FOUND);
  return next(err);
});

// log error in winston transports except when executing test suite
if (config.env !== 'test') {
  app.use(expressWinston.errorLogger({
    winstonInstance
  }));
}

// error handler, send stacktrace only during development
app.use((err, req, res, next) => // eslint-disable-line no-unused-vars
  res.status(err.status).json({
    message: err.isPublic ? err.message : httpStatus[err.status],
    stack: config.env === 'development' ? err.stack : {}
  })
);

export default app;
github pixeloven / pixeloven / apps / examples / react-ssr-example / src / server / server.ts View on Github external
router.get("/api/v1/health", health);
    router.all("/api/*", (req, res, next) => {
        res.status(404).send();
    });
    app.use(config.publicPath, router);

    /**
     * Register endpoints
     */
    app.use(renderer(config));

    /**
     * Setup express error handling
     */
    app.use(
        expressWinston.errorLogger({
            transports: [new winston.transports.Console()],
        }),
    );
    app.use(errorHandler(config));
}
github vincentbernat / dashkiosk / lib / logger.js View on Github external
error: function(app) {
    app.use(expressWinston.errorLogger({
      transports: transports
    }));
  },
github jiayisheji / jianshu / service / src / app / expresswinston.filter.ts View on Github external
app.use(expressWinston.logger({
        transports: [
            new (winston.transports.Console)({
                json: true,
                colorize: true
            }),
            new winston.transports.File({
                filename: 'logs/success.log'
            })
        ]
    }));

    /**
     * 错误日志
     */
    app.use(expressWinston.errorLogger({
        transports: [
            new winston.transports.Console({
                json: true,
                colorize: true
            }),
            new winston.transports.File({
                filename: 'logs/error.log'
            })
        ]
    }));
}
github ExpediaDotCom / haystack-ui / server / utils / logger.js View on Github external
}

exports.withIdentifier = (identifier) => {
    if (!identifier) {
        throw new Error('Identifier is required while setting up a logger. For example, pass the module name that will use this logger.');
    }
    return new winston.Logger({
        transports: [new winston.transports.Console(_.merge({}, CONSOLE_TRANSPORT_OPTIONS, getLogFormatterOptionsWithIdentifier(identifier)))]
    });
};

exports.REQUEST_LOGGER = expressWinston.logger({
    transports: [new winston.transports.Console(CONSOLE_TRANSPORT_OPTIONS)]
});

exports.ERROR_LOGGER = expressWinston.errorLogger({
    transports: [new winston.transports.Console(CONSOLE_TRANSPORT_OPTIONS)]
});
github paypal / appsforhere / index.js View on Github external
app.on('middleware:after:router', function addExpressWinston() {
        app.use(expressWinston.errorLogger({
            winstonInstance: logger._impl
        }));
    });

express-winston

express.js middleware for winstonjs/winston

MIT
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis