Define global logger instance to be used for all logging
Summary: The advantage of this is that anyone can now log without needing to carry around a Logger object. Primary reason is for making metrics less intrusive in the codebase. Reviewed By: passy Differential Revision: D13671368 fbshipit-source-id: 162ab1351a124683aef13983fc3bcec01385cd1a
This commit is contained in:
committed by
Facebook Github Bot
parent
e71804fe9e
commit
3bcb079f87
@@ -5,7 +5,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type Logger from '../fb-stubs/Logger';
|
||||
import {getInstance} from '../fb-stubs/Logger';
|
||||
|
||||
/*
|
||||
* Wraps a Promise, preserving it's functionality but logging the success or
|
||||
@@ -15,15 +15,14 @@ import type Logger from '../fb-stubs/Logger';
|
||||
export function recordSuccessMetric(
|
||||
promise: Promise<*>,
|
||||
name: string,
|
||||
logger: Logger,
|
||||
): Promise<*> {
|
||||
return promise.then(
|
||||
fulfilledValue => {
|
||||
logger.track('success-rate', name, 1);
|
||||
getInstance().track('success-rate', name, 1);
|
||||
return fulfilledValue;
|
||||
},
|
||||
rejectionReason => {
|
||||
logger.track('success-rate', name, 0);
|
||||
getInstance().track('success-rate', name, 0);
|
||||
return Promise.reject(rejectionReason);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user