Skip to content

Commit 27d1e9e

Browse files
committed
feat: missing logger migrations
1 parent eb930e8 commit 27d1e9e

File tree

7 files changed

+44
-31
lines changed

7 files changed

+44
-31
lines changed

packages/event-listener/src/lib/actions/log-context.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { logger } from '@lit-protocol/logger';
2+
13
import { Action } from './action';
24
import { StateMachine } from '../state-machine';
35

@@ -10,10 +12,10 @@ interface LogContextActionParams {
1012
export class LogContextAction extends Action {
1113
constructor(params: LogContextActionParams) {
1214
const logContextFunction = async () => {
13-
console.log(
14-
`State Machine context: `,
15-
params.stateMachine.getFromContext(params.path)
16-
);
15+
logger.info({
16+
msg: `State Machine context`,
17+
context: params.stateMachine.getFromContext(params.path),
18+
});
1719
};
1820

1921
super({

packages/event-listener/src/lib/actions/mint-pkp.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { logger } from '@lit-protocol/logger';
2+
13
import { Action } from './action';
24
import { StateMachine } from '../state-machine';
35

@@ -12,7 +14,7 @@ export class MintPkpAction extends Action {
1214
const mintingReceipt =
1315
await params.stateMachine.litContracts.pkpNftContractUtils.write.mint();
1416
const pkp = mintingReceipt.pkp;
15-
params.debug && console.log(`Minted PKP: ${pkp}`);
17+
params.debug && logger.info(`Minted PKP: ${pkp}`);
1618
params.stateMachine.setToContext('activePkp', pkp);
1719
};
1820

packages/event-listener/src/lib/listeners/fetch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { logger } from '@lit-protocol/logger';
2+
13
import { Listener } from './listener';
24

35
interface FetchListenerConfig {
@@ -32,7 +34,7 @@ export class FetchListener extends Listener<any> {
3234
this.emit(value);
3335
}
3436
} catch (error) {
35-
console.error('FetchListener error:', error);
37+
logger.error({ msg: 'FetchListener error:', error });
3638
}
3739
}, pollInterval);
3840
},

packages/event-listener/src/lib/state-machine.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@lit-protocol/constants';
88
import { LitContracts } from '@lit-protocol/contracts-sdk';
99
import { LitNodeClient } from '@lit-protocol/lit-node-client';
10+
import { logger } from '@lit-protocol/logger';
1011

1112
import {
1213
Action,
@@ -382,17 +383,17 @@ export class StateMachine {
382383
// Aggregate (AND) all listener checks to a single function result
383384
transitionConfig.check = async (values) => {
384385
this.debug &&
385-
console.log(
386-
`${transitionDefinition.fromState} -> ${transitionDefinition.toState} values`,
387-
values
388-
);
386+
logger.info({
387+
msg: `${transitionDefinition.fromState} -> ${transitionDefinition.toState} values`,
388+
values,
389+
});
389390
return Promise.all(checks.map((check) => check(values))).then(
390391
(results) => {
391392
this.debug &&
392-
console.log(
393-
`${transitionDefinition.fromState} -> ${transitionDefinition.toState} results`,
394-
results
395-
);
393+
logger.info({
394+
msg: `${transitionDefinition.fromState} -> ${transitionDefinition.toState} results`,
395+
results,
396+
});
396397
return results.every((result) => result);
397398
}
398399
);
@@ -410,7 +411,7 @@ export class StateMachine {
410411
initialState: string,
411412
onStop?: voidAsyncFunction
412413
): Promise<void> {
413-
this.debug && console.log('Starting state machine...');
414+
this.debug && logger.info('Starting state machine...');
414415

415416
await Promise.all([
416417
this.litContracts.connect(),
@@ -421,7 +422,7 @@ export class StateMachine {
421422
await this.enterState(initialState);
422423
this.status = 'running';
423424

424-
this.debug && console.log('State machine started');
425+
this.debug && logger.info('State machine started');
425426
}
426427

427428
/**
@@ -470,20 +471,21 @@ export class StateMachine {
470471
* Stops the state machine by exiting the current state and not moving to another one.
471472
*/
472473
public async stopMachine(): Promise<void> {
473-
this.debug && console.log('Stopping state machine...');
474+
this.debug && logger.info('Stopping state machine...');
474475

475476
this.status = 'stopped';
476477
await this.exitCurrentState();
477478
await this.onStopCallback?.();
478479

479-
this.debug && console.log('State machine stopped');
480+
this.debug && logger.info('State machine stopped');
480481
}
481482

482483
/**
483484
* Stops listening on the current state's transitions and exits the current state.
484485
*/
485486
private async exitCurrentState(): Promise<void> {
486-
this.debug && console.log('exitCurrentState', this.currentState?.key);
487+
this.debug &&
488+
logger.info({ msg: 'exitCurrentState', state: this.currentState?.key });
487489

488490
const currentTransitions =
489491
this.transitions.get(this.currentState?.key ?? '') ??
@@ -514,7 +516,7 @@ export class StateMachine {
514516
`State ${stateKey} not found`
515517
);
516518
}
517-
this.debug && console.log('enterState', state.key);
519+
this.debug && logger.info({ msg: 'enterState', state: state.key });
518520
await state.enter();
519521
const nextTransitions =
520522
this.transitions.get(state.key) ?? new Map<string, Transition>();
@@ -542,7 +544,7 @@ export class StateMachine {
542544
);
543545
}
544546
if (this.currentState === nextState) {
545-
console.warn(
547+
logger.warn(
546548
`State ${stateKey} is already active. Skipping state change.`
547549
);
548550
return;
@@ -615,7 +617,7 @@ export class StateMachine {
615617
}
616618
if (this.debug) {
617619
const activePkp = this.context.get('activePkp');
618-
console.log(`Machine configured to use pkp ${activePkp}`);
620+
logger.info(`Machine configured to use pkp ${activePkp}`);
619621
}
620622
break;
621623
default:
@@ -665,7 +667,7 @@ export class StateMachine {
665667
}
666668

667669
// Throwing when stopping could hide above error
668-
this.stopMachine().catch(console.error);
670+
this.stopMachine().catch((error) => logger.error({ error }));
669671
}
670672
}
671673

packages/event-listener/src/lib/states/state.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { logger } from '@lit-protocol/logger';
2+
13
import { voidAsyncFunction } from '../types';
24

35
export interface BaseStateParams {
@@ -29,15 +31,15 @@ export class State {
2931
* Executes the onEnter action for the state.
3032
*/
3133
async enter() {
32-
this.debug && console.log(`enter ${this.key}`);
34+
this.debug && logger.info(`enter ${this.key}`);
3335
await this.onEnter?.();
3436
}
3537

3638
/**
3739
* Executes the onExit action for the state.
3840
*/
3941
async exit() {
40-
this.debug && console.log(`exit ${this.key}`);
42+
this.debug && logger.info(`exit ${this.key}`);
4143
await this.onExit?.();
4244
}
4345
}

packages/event-listener/src/lib/transitions/transition.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { logger } from '@lit-protocol/logger';
2+
13
import { Listener } from '../listeners';
24
import { onError } from '../types';
35

@@ -75,13 +77,13 @@ export class Transition {
7577
*/
7678
async startListening() {
7779
try {
78-
this.debug && console.log('startListening');
80+
this.debug && logger.info('startListening');
7981
await Promise.all(this.listeners.map((listener) => listener.start()));
8082

8183
if (!this.listeners.length) {
8284
// If the transition does not have any listeners it will never emit. Therefore, we "match" automatically on next event loop
8385
setTimeout(() => {
84-
this.debug && console.log('Transition without listeners: auto match');
86+
this.debug && logger.info('Transition without listeners: auto match');
8587
this.onMatch([]);
8688
}, 0);
8789
}
@@ -99,7 +101,7 @@ export class Transition {
99101
*/
100102
async stopListening() {
101103
try {
102-
this.debug && console.log('stopListening');
104+
this.debug && logger.info('stopListening');
103105
this.queue.length = 0; // Flush the queue as there might be more value arrays to check
104106
await Promise.all(this.listeners.map((listener) => listener.stop()));
105107
} catch (e) {
@@ -129,10 +131,10 @@ export class Transition {
129131
const isMatch = this.check ? await this.check(currentValues) : true;
130132

131133
if (isMatch) {
132-
this.debug && console.log('match', currentValues);
134+
this.debug && logger.info({ msg: 'match', values: currentValues });
133135
await this.onMatch?.(currentValues);
134136
} else {
135-
this.debug && console.log('mismatch', currentValues);
137+
this.debug && logger.info({ msg: 'mismatch', values: currentValues });
136138
await this.onMismatch?.(currentValues);
137139
}
138140
}

packages/lit-node-client/src/lib/helpers/mint-claim-callback.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
RELAYER_URL_BY_NETWORK,
77
WrongNetworkException,
88
} from '@lit-protocol/constants';
9+
import { logger } from '@lit-protocol/logger';
910
import {
1011
ClaimResult,
1112
MintCallback,
@@ -77,7 +78,7 @@ export const defaultMintClaimCallback: MintCallback<
7778
const errStmt = `An error occurred requesting "/auth/claim" endpoint ${JSON.stringify(
7879
errResp
7980
)}`;
80-
console.warn(errStmt);
81+
logger.warn(errStmt);
8182
throw new NetworkError(
8283
{
8384
info: {

0 commit comments

Comments
 (0)