log: change log format to JSON payload for better log in Stackdriver (#66)
change the log format in Python and Node.js services. Effected services are currencyservice, emailservice, paymentservice, and recommendationservice. Loadgenerator is left as is because of the diffculty to change the log format and log target in locust. ref. #47
This commit is contained in:
parent
2771a03727
commit
7f40378ecc
16 changed files with 286 additions and 35 deletions
|
@ -14,6 +14,15 @@
|
|||
|
||||
const cardValidator = require('simple-card-validator');
|
||||
const uuid = require('uuid/v4');
|
||||
const pino = require('pino');
|
||||
|
||||
const logger = pino({
|
||||
name: 'paymentservice-charge',
|
||||
messageKey: 'message',
|
||||
changeLevelName: 'severity',
|
||||
useLevelLabels: true
|
||||
});
|
||||
|
||||
|
||||
class CreditCardError extends Error {
|
||||
constructor (message) {
|
||||
|
@ -67,7 +76,7 @@ module.exports = function charge (request) {
|
|||
const { credit_card_expiration_year: year, credit_card_expiration_month: month } = creditCard;
|
||||
if ((currentYear * 12 + currentMonth) > (year * 12 + month)) { throw new ExpiredCreditCard(cardNumber.replace('-', ''), month, year); }
|
||||
|
||||
console.log(`Transaction processed: ${cardType} ending ${cardNumber.substr(-4)} \
|
||||
logger.info(`Transaction processed: ${cardType} ending ${cardNumber.substr(-4)} \
|
||||
Amount: ${amount.currency_code}${amount.units}.${amount.nanos}`);
|
||||
|
||||
return { transaction_id: uuid() };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue