start to add logging
This commit is contained in:
@@ -13,6 +13,8 @@
|
|||||||
"express": "^4.15.4",
|
"express": "^4.15.4",
|
||||||
"redis": "^2.8.0",
|
"redis": "^2.8.0",
|
||||||
"request": "^2.83.0",
|
"request": "^2.83.0",
|
||||||
|
"express-pino-logger": "^4.0.0",
|
||||||
|
"pino-pretty": "^2.5.0",
|
||||||
"instana-nodejs-sensor": "^1.28.0"
|
"instana-nodejs-sensor": "^1.28.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,14 +11,22 @@ const redis = require('redis');
|
|||||||
const request = require('request');
|
const request = require('request');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
const pino = require('express-pino-logger');
|
||||||
|
|
||||||
var redisConnected = false;
|
var redisConnected = false;
|
||||||
|
|
||||||
var redisHost = process.env.REDIS_HOST || 'redis'
|
var redisHost = process.env.REDIS_HOST || 'redis'
|
||||||
var catalogueHost = process.env.CATALOGUE_HOST || 'catalogue'
|
var catalogueHost = process.env.CATALOGUE_HOST || 'catalogue'
|
||||||
|
|
||||||
|
const logger = pino({
|
||||||
|
level: 'info',
|
||||||
|
prettyPrint: true,
|
||||||
|
useLevelLabels: true
|
||||||
|
});
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
app.use(logger);
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
res.set('Timing-Allow-Origin', '*');
|
res.set('Timing-Allow-Origin', '*');
|
||||||
res.set('Access-Control-Allow-Origin', '*');
|
res.set('Access-Control-Allow-Origin', '*');
|
||||||
@@ -29,6 +37,7 @@ app.use(bodyParser.urlencoded({ extended: true }));
|
|||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
app.get('/health', (req, res) => {
|
app.get('/health', (req, res) => {
|
||||||
|
req.log.info('Health check');
|
||||||
var stat = {
|
var stat = {
|
||||||
app: 'OK',
|
app: 'OK',
|
||||||
redis: redisConnected
|
redis: redisConnected
|
||||||
@@ -41,7 +50,7 @@ app.get('/health', (req, res) => {
|
|||||||
app.get('/cart/:id', (req, res) => {
|
app.get('/cart/:id', (req, res) => {
|
||||||
redisClient.get(req.params.id, (err, data) => {
|
redisClient.get(req.params.id, (err, data) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
console.log('ERROR', err);
|
req.log.error('ERROR', err);
|
||||||
res.status(500).send(err);
|
res.status(500).send(err);
|
||||||
} else {
|
} else {
|
||||||
if(data == null) {
|
if(data == null) {
|
||||||
@@ -315,15 +324,15 @@ var redisClient = redis.createClient({
|
|||||||
});
|
});
|
||||||
|
|
||||||
redisClient.on('error', (e) => {
|
redisClient.on('error', (e) => {
|
||||||
console.log('Redis ERROR', e);
|
console.error('Redis ERROR', e);
|
||||||
});
|
});
|
||||||
redisClient.on('ready', (r) => {
|
redisClient.on('ready', (r) => {
|
||||||
console.log('Redis READY', r);
|
console.info('Redis READY', r);
|
||||||
redisConnected = true;
|
redisConnected = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// fire it up!
|
// fire it up!
|
||||||
const port = process.env.CART_SERVER_PORT || '8080';
|
const port = process.env.CART_SERVER_PORT || '8080';
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log('Started on port', port);
|
console.info('Started on port', port);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user