@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
53 lines • 2.57 kB
JavaScript
import { callConsoleMessage } from './utils.js';
export const Logger = function (headMessage = 'LOG:') {
return function LoggerDecorator(target, context) {
const methodName = String(context.name);
if (context.kind === 'getter') {
const replacementGetter = function () {
if (headMessage === 'Deprecation:')
callConsoleMessage.call(this, headMessage, `Getter '${methodName}' is being deprecated in the next major version`);
callConsoleMessage.call(this, headMessage, `Accessing getter '${methodName}'.`);
const result = target.call(this);
if (result instanceof Promise) {
return result
.then((resolvedResult) => {
callConsoleMessage.call(this, headMessage, `Getter '${methodName}' resolved.`);
return resolvedResult;
})
.catch((error) => {
callConsoleMessage.call(this, headMessage, `Getter '${methodName}' rejected with error.`, 'Error:');
throw error;
});
}
else {
callConsoleMessage.call(this, headMessage, `Getter '${methodName}' accessed.`);
return result;
}
};
return replacementGetter;
}
const replacementMethod = function (...args) {
if (headMessage === 'Deprecation:')
callConsoleMessage.call(this, headMessage, `Method '${methodName}' is being deprecated in the next major version`);
callConsoleMessage.call(this, headMessage, `Entering method '${methodName}'.`);
const result = target.call(this, ...args);
if (result instanceof Promise) {
return result
.then((resolvedResult) => {
callConsoleMessage.call(this, headMessage, `Exiting method '${methodName}'.`);
return resolvedResult;
})
.catch((error) => {
callConsoleMessage.call(this, headMessage, `Exiting method '${methodName}' with error.`, 'Error:');
throw error;
});
}
else {
callConsoleMessage.call(this, headMessage, `Exiting method '${methodName}'.`);
return result;
}
};
return replacementMethod;
};
};
//# sourceMappingURL=logger.js.map