File tree Expand file tree Collapse file tree 5 files changed +50
-0
lines changed Expand file tree Collapse file tree 5 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import {
24
24
NetworkStateTransportModule ,
25
25
DummyStateService ,
26
26
WorkerReadyModule ,
27
+ ConsoleLoggingFactory ,
27
28
} from "@proto-kit/sequencer" ;
28
29
import {
29
30
NetworkState ,
@@ -314,6 +315,7 @@ export class AppChain<
314
315
315
316
this . useDependencyFactory ( this . container . resolve ( AreProofsEnabledFactory ) ) ;
316
317
this . useDependencyFactory ( this . container . resolve ( SharedDependencyFactory ) ) ;
318
+ this . useDependencyFactory ( this . container . resolve ( ConsoleLoggingFactory ) ) ;
317
319
318
320
this . container
319
321
. resolve < AreProofsEnabled > ( "AreProofsEnabled" )
Original file line number Diff line number Diff line change @@ -96,3 +96,6 @@ export * from "./settlement/tasks/SettlementProvingTask";
96
96
export * from "./settlement/transactions/MinaTransactionSender" ;
97
97
export * from "./settlement/transactions/MinaTransactionSimulator" ;
98
98
export * from "./settlement/transactions/MinaSimulationService" ;
99
+ export * from "./logging/Tracer" ;
100
+ export * from "./logging/ConsoleLoggingFactory" ;
101
+ export * from "./logging/ConsoleTracer" ;
Original file line number Diff line number Diff line change
1
+ import { injectable } from "tsyringe" ;
2
+ import { DependencyFactory , DependencyRecord } from "@proto-kit/common" ;
3
+
4
+ import { ConsoleTracer } from "./ConsoleTracer" ;
5
+
6
+ @injectable ( )
7
+ export class ConsoleLoggingFactory implements DependencyFactory {
8
+ public dependencies ( ) {
9
+ return {
10
+ Tracer : {
11
+ useClass : ConsoleTracer ,
12
+ } ,
13
+ } satisfies DependencyRecord ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ import { injectable } from "tsyringe" ;
2
+ import { log } from "@proto-kit/common" ;
3
+
4
+ import { Tracer } from "./Tracer" ;
5
+
6
+ @injectable ( )
7
+ export class ConsoleTracer implements Tracer {
8
+ public async trace < T > (
9
+ name : string ,
10
+ f : ( ) => Promise < T > ,
11
+ metadata ?: Record < string , string | number | boolean >
12
+ ) : Promise < T > {
13
+ const timeStart = Date . now ( ) ;
14
+ const result = await f ( ) ;
15
+ const message = `Routine ${ name } took ${ Date . now ( ) - timeStart } ms` ;
16
+ if ( metadata !== undefined ) {
17
+ log . info ( message , metadata ) ;
18
+ } else {
19
+ log . info ( message ) ;
20
+ }
21
+ return result ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ export interface Tracer {
2
+ trace < T > (
3
+ name : string ,
4
+ f : ( ) => Promise < T > ,
5
+ metadata ?: Record < string , string | number | boolean >
6
+ ) : Promise < T > ;
7
+ }
You can’t perform that action at this time.
0 commit comments