@adapty/capacitor
Version:
Official Adapty SDK for Capacitor
61 lines • 2.63 kB
JavaScript
import { Log } from './log';
import { LogScope } from './log-scope';
// LogContext instance is a logger context for a single call to a native SDK method
// It accumulates logs for each step of the call
export class LogContext {
constructor() {
this.stack = [];
}
createScope(step, args, message) {
return new LogScope(Object.assign(Object.assign({}, args), { onStart: (payload) => {
this.stack.push({ action: step, fn: args.methodName, payload });
Log.verbose(args.methodName, () => `${message}...`, () => payload());
}, onSuccess: (payload) => {
this.stack.push({
action: step,
fn: args.methodName,
payload,
done: true,
});
Log.verbose(args.methodName, () => `${message}: OK`, () => payload());
}, onFailed: (payload) => {
this.stack.push({
action: step,
fn: args.methodName,
payload,
error: true,
});
const resolvedStack = this.stack.map(s => (Object.assign(Object.assign({}, s), { payload: s.payload() })));
const p = payload();
p['__stack__'] = resolvedStack;
Log.error(args.methodName, () => `${message}: FAILED`, () => p);
}, onWait: (payload) => {
this.stack.push({ action: step, fn: args.methodName, payload });
Log.verbose(args.methodName, () => `<HOLD> ${message}`, () => payload());
}, onWaitComplete: (payload) => {
this.stack.push({ action: step, fn: args.methodName, payload });
Log.verbose(args.methodName, () => `<UNLOCKED> ${message}`, () => payload());
} }));
}
// Creates a scope for a event listener
event(method) {
return this.createScope('EVENT', method, `Receiving event "${method.methodName}"`);
}
// Create a scope for a public call
call(args) {
return this.createScope('CALL', args, 'Calling method');
}
// Creates a scope for encoding an object
encode(args) {
return this.createScope('ENCODE', args, 'Encoding object');
}
// Creates a scope for calling a bridge function
bridge(args) {
return this.createScope('BRIDGE', args, 'Calling bridge function');
}
// Creates a scope for decoding a string
decode(args) {
return this.createScope('DECODE', args, 'Decoding string');
}
}
//# sourceMappingURL=log-context.js.map