mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-21 09:05:10 +00:00
Update logging
Signed-off-by: James Taylor <jamest@uk.ibm.com>
This commit is contained in:
parent
d9e0de606b
commit
f06f1eed4b
2 changed files with 22 additions and 20 deletions
|
|
@ -35,7 +35,7 @@ assetsRouter.post(
|
||||||
body('owner', 'must be a string').notEmpty(),
|
body('owner', 'must be a string').notEmpty(),
|
||||||
body('appraisedValue', 'must be a number').isNumeric(),
|
body('appraisedValue', 'must be a number').isNumeric(),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
logger.info(req.body, 'Create asset request received');
|
logger.debug(req.body, 'Create asset request received');
|
||||||
|
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
|
|
@ -93,7 +93,7 @@ assetsRouter.post(
|
||||||
// codes that can be checked.
|
// codes that can be checked.
|
||||||
await clearTransactionDetails(redis, txnId);
|
await clearTransactionDetails(redis, txnId);
|
||||||
|
|
||||||
logger.error(err);
|
logger.error(err, 'Error processing create asset request for asset ID %s with transaction ID %s', req.body.id, txnId);
|
||||||
return res.status(INTERNAL_SERVER_ERROR).json({
|
return res.status(INTERNAL_SERVER_ERROR).json({
|
||||||
status: getReasonPhrase(INTERNAL_SERVER_ERROR),
|
status: getReasonPhrase(INTERNAL_SERVER_ERROR),
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
|
|
@ -103,12 +103,12 @@ assetsRouter.post(
|
||||||
);
|
);
|
||||||
|
|
||||||
assetsRouter.options('/:assetId', async (req: Request, res: Response) => {
|
assetsRouter.options('/:assetId', async (req: Request, res: Response) => {
|
||||||
logger.info(req.body, 'Read asset request received');
|
const assetId = req.params.assetId;
|
||||||
|
logger.debug('Asset options request received for asset ID %s', assetId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const contract: Contract = req.app.get('contract');
|
const contract: Contract = req.app.get('contract');
|
||||||
|
|
||||||
const assetId = req.params.assetId;
|
|
||||||
const data = await contract.evaluateTransaction('AssetExists', assetId);
|
const data = await contract.evaluateTransaction('AssetExists', assetId);
|
||||||
const exists = data.toString() === 'true';
|
const exists = data.toString() === 'true';
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ assetsRouter.options('/:assetId', async (req: Request, res: Response) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err, 'Error processing asset options request for asset ID %s', assetId);
|
||||||
return res.status(INTERNAL_SERVER_ERROR).json({
|
return res.status(INTERNAL_SERVER_ERROR).json({
|
||||||
status: getReasonPhrase(INTERNAL_SERVER_ERROR),
|
status: getReasonPhrase(INTERNAL_SERVER_ERROR),
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
|
|
@ -138,16 +138,18 @@ assetsRouter.options('/:assetId', async (req: Request, res: Response) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
assetsRouter.get('/:assetId', async (req: Request, res: Response) => {
|
assetsRouter.get('/:assetId', async (req: Request, res: Response) => {
|
||||||
|
const assetId = req.params.assetId;
|
||||||
|
logger.debug('Read asset request received for asset ID %s', assetId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const contract: Contract = req.app.get('contract');
|
const contract: Contract = req.app.get('contract');
|
||||||
|
|
||||||
const assetId = req.params.assetId;
|
|
||||||
const data = await contract.evaluateTransaction('ReadAsset', assetId);
|
const data = await contract.evaluateTransaction('ReadAsset', assetId);
|
||||||
const asset = JSON.parse(data.toString());
|
const asset = JSON.parse(data.toString());
|
||||||
|
|
||||||
return res.status(OK).json(asset);
|
return res.status(OK).json(asset);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err, 'Error processing read asset request for asset ID %s', assetId);
|
||||||
return res.status(INTERNAL_SERVER_ERROR).json({
|
return res.status(INTERNAL_SERVER_ERROR).json({
|
||||||
status: getReasonPhrase(INTERNAL_SERVER_ERROR),
|
status: getReasonPhrase(INTERNAL_SERVER_ERROR),
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ export const createDeferredEventHandler = (
|
||||||
|
|
||||||
const removeCommitListener = async () => {
|
const removeCommitListener = async () => {
|
||||||
network.removeCommitListener(listener);
|
network.removeCommitListener(listener);
|
||||||
logger.info('Stopped listening for transaction %s events', transactionId);
|
logger.debug('Stopped listening for transaction %s events', transactionId);
|
||||||
|
|
||||||
const txnExists = await redis.exists(transactionId);
|
const txnExists = await redis.exists(transactionId);
|
||||||
if (txnExists) {
|
if (txnExists) {
|
||||||
|
|
@ -92,7 +92,7 @@ export const createDeferredEventHandler = (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event && event.isValid) {
|
if (event && event.isValid) {
|
||||||
logger.info('Transaction %s successfully committed', transactionId);
|
logger.debug('Transaction %s successfully committed', transactionId);
|
||||||
|
|
||||||
await clearTransactionDetails(redis, transactionId);
|
await clearTransactionDetails(redis, transactionId);
|
||||||
await removeCommitListener();
|
await removeCommitListener();
|
||||||
|
|
@ -101,9 +101,9 @@ export const createDeferredEventHandler = (
|
||||||
|
|
||||||
const deferredEventHandler: TxEventHandler = {
|
const deferredEventHandler: TxEventHandler = {
|
||||||
startListening: async () => {
|
startListening: async () => {
|
||||||
logger.info('Setting timeout for %d ms', options.commitTimeout * 1000);
|
logger.debug('Setting timeout for %d ms', options.commitTimeout * 1000);
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
logger.info(
|
logger.debug(
|
||||||
'Timeout listening for transaction %s events',
|
'Timeout listening for transaction %s events',
|
||||||
transactionId
|
transactionId
|
||||||
);
|
);
|
||||||
|
|
@ -111,14 +111,14 @@ export const createDeferredEventHandler = (
|
||||||
}, options.commitTimeout * 1000);
|
}, options.commitTimeout * 1000);
|
||||||
|
|
||||||
await network.addCommitListener(listener, peers, transactionId);
|
await network.addCommitListener(listener, peers, transactionId);
|
||||||
logger.info('Listening for transaction %s events', transactionId);
|
logger.debug('Listening for transaction %s events', transactionId);
|
||||||
},
|
},
|
||||||
waitForEvents: async () => {
|
waitForEvents: async () => {
|
||||||
// No-op
|
// No-op
|
||||||
},
|
},
|
||||||
cancelListening: async () => {
|
cancelListening: async () => {
|
||||||
// TODO this is what the doc says, but is it true?!
|
// TODO this is what the doc says, but is it true?!
|
||||||
logger.info(
|
logger.warn(
|
||||||
'Submission of transaction %s to the orderer failed',
|
'Submission of transaction %s to the orderer failed',
|
||||||
transactionId
|
transactionId
|
||||||
);
|
);
|
||||||
|
|
@ -137,7 +137,7 @@ export const startRetryLoop = (contract: Contract, redis: Redis): void => {
|
||||||
const pendingTransactionCount = await (redis as Redis).zcard(
|
const pendingTransactionCount = await (redis as Redis).zcard(
|
||||||
'index:txn:timestamp'
|
'index:txn:timestamp'
|
||||||
);
|
);
|
||||||
logger.info('Transactions awaiting retry: %d', pendingTransactionCount);
|
logger.debug('Transactions awaiting retry: %d', pendingTransactionCount);
|
||||||
|
|
||||||
const transactionIds = await (redis as Redis).zrange(
|
const transactionIds = await (redis as Redis).zrange(
|
||||||
'index:txn:timestamp',
|
'index:txn:timestamp',
|
||||||
|
|
@ -174,7 +174,7 @@ const retryTransaction = async (
|
||||||
transactionId: string,
|
transactionId: string,
|
||||||
savedTransaction: Record<string, string>
|
savedTransaction: Record<string, string>
|
||||||
) => {
|
) => {
|
||||||
logger.info('Retrying transaction %s', transactionId);
|
logger.debug('Retrying transaction %s', transactionId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const transaction = contract.deserializeTransaction(
|
const transaction = contract.deserializeTransaction(
|
||||||
|
|
@ -186,7 +186,7 @@ const retryTransaction = async (
|
||||||
await clearTransactionDetails(redis, transactionId);
|
await clearTransactionDetails(redis, transactionId);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (isDuplicateTransaction(err)) {
|
if (isDuplicateTransaction(err)) {
|
||||||
logger.info('Transaction %s has already been committed', transactionId);
|
logger.debug('Transaction %s has already been committed', transactionId);
|
||||||
await clearTransactionDetails(redis, transactionId);
|
await clearTransactionDetails(redis, transactionId);
|
||||||
} else {
|
} else {
|
||||||
// TODO check for retry limit and update timestamp
|
// TODO check for retry limit and update timestamp
|
||||||
|
|
@ -214,7 +214,7 @@ const isDuplicateTransaction = (error: {
|
||||||
|
|
||||||
return isDuplicateTxn;
|
return isDuplicateTxn;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn(err, 'error checking for duplicate transaction');
|
logger.warn(err, 'Error checking for duplicate transaction');
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -230,7 +230,7 @@ export const storeTransactionDetails = async (
|
||||||
timestamp: number
|
timestamp: number
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const key = `txn:${transactionId}`;
|
const key = `txn:${transactionId}`;
|
||||||
logger.info(
|
logger.debug(
|
||||||
'Storing transaction details. Key: %s State: %s Args: %s Timestamp: %d',
|
'Storing transaction details. Key: %s State: %s Args: %s Timestamp: %d',
|
||||||
key,
|
key,
|
||||||
transactionState,
|
transactionState,
|
||||||
|
|
@ -259,7 +259,7 @@ export const clearTransactionDetails = async (
|
||||||
transactionId: string
|
transactionId: string
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const key = `txn:${transactionId}`;
|
const key = `txn:${transactionId}`;
|
||||||
logger.info('Removing transaction details. Key: %s', key);
|
logger.debug('Removing transaction details. Key: %s', key);
|
||||||
try {
|
try {
|
||||||
await redis
|
await redis
|
||||||
.multi()
|
.multi()
|
||||||
|
|
@ -267,6 +267,6 @@ export const clearTransactionDetails = async (
|
||||||
.zrem('index:txn:timestamp', transactionId)
|
.zrem('index:txn:timestamp', transactionId)
|
||||||
.exec();
|
.exec();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err, 'error remove saved transaction state');
|
logger.error(err, 'Error remove saved transaction state for transaction ID %s', transactionId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue