1414namespace bb ::nodejs {
1515
1616namespace {
17+ // Log levels from TS foundation/src/log/log-levels.ts: ['silent', 'fatal', 'error', 'warn', 'info', 'verbose', 'debug',
18+ // 'trace'] Map: 0=silent, 1=fatal, 2=error, 3=warn, 4=info, 5=verbose, 6=debug, 7=trace
19+ constexpr int LOG_LEVEL_VERBOSE = 5 ;
20+ constexpr int LOG_LEVEL_TRACE = 7 ;
21+
22+ // Helper to set logging flags based on TS log level
23+ inline void set_logging_from_level (int log_level)
24+ {
25+ // Turn verbose_logging on if log level is verbose (5) or above
26+ verbose_logging = (log_level >= LOG_LEVEL_VERBOSE);
27+ // Turn debug_logging on if log level is trace (7) or above
28+ debug_logging = (log_level >= LOG_LEVEL_TRACE);
29+ }
30+
1731// Callback method names
1832constexpr const char * CALLBACK_GET_CONTRACT_INSTANCE = " getContractInstance" ;
1933constexpr const char * CALLBACK_GET_CONTRACT_CLASS = " getContractClass" ;
@@ -100,20 +114,17 @@ struct ContractCallbacks {
100114
101115Napi::Value AvmSimulateNapi::simulate (const Napi::CallbackInfo& cb_info)
102116{
103- // TODO(dbanks12): configurable verbosity (maybe based on TS log level)
104- // verbose_logging = true;
105- // debug_logging = true;
106-
107117 Napi::Env env = cb_info.Env ();
108118
109- // Validate arguments - expects 3 arguments
119+ // Validate arguments - expects 4 arguments
110120 // arg[0]: inputs Buffer (required)
111121 // arg[1]: contractProvider object (required)
112122 // arg[2]: worldStateHandle external (required)
113- if (cb_info.Length () < 3 ) {
123+ // arg[3]: logLevel number (required) - index into TS LogLevels array
124+ if (cb_info.Length () < 4 ) {
114125 throw Napi::TypeError::New (env,
115- " Wrong number of arguments. Expected 3 arguments: inputs Buffer, contractProvider "
116- " object, and worldStateHandle ." );
126+ " Wrong number of arguments. Expected 4 arguments: inputs Buffer, contractProvider "
127+ " object, worldStateHandle, and logLevel ." );
117128 }
118129
119130 if (!cb_info[0 ].IsBuffer ()) {
@@ -129,6 +140,14 @@ Napi::Value AvmSimulateNapi::simulate(const Napi::CallbackInfo& cb_info)
129140 throw Napi::TypeError::New (env, " Third argument must be a WorldState handle (External)" );
130141 }
131142
143+ if (!cb_info[3 ].IsNumber ()) {
144+ throw Napi::TypeError::New (env, " Fourth argument must be a log level number (0-7)" );
145+ }
146+
147+ // Extract log level and set logging flags
148+ int log_level = cb_info[3 ].As <Napi::Number>().Int32Value ();
149+ set_logging_from_level (log_level);
150+
132151 // Extract the inputs buffer
133152 auto inputs_buffer = cb_info[0 ].As <Napi::Buffer<uint8_t >>();
134153 size_t length = inputs_buffer.Length ();
@@ -215,24 +234,30 @@ Napi::Value AvmSimulateNapi::simulate(const Napi::CallbackInfo& cb_info)
215234
216235Napi::Value AvmSimulateNapi::simulateWithHintedDbs (const Napi::CallbackInfo& cb_info)
217236{
218- // TODO(dbanks12): configurable verbosity (maybe based on TS log level)
219- verbose_logging = true ;
220- debug_logging = true ;
221-
222237 Napi::Env env = cb_info.Env ();
223238
224- // Validate arguments - expects 1 argument
239+ // Validate arguments - expects 2 arguments
225240 // arg[0]: inputs Buffer (required) - AvmProvingInputs
226- if (cb_info.Length () < 1 ) {
227- throw Napi::TypeError::New (
228- env, " Wrong number of arguments. Expected 1 argument: AvmProvingInputs/AvmCircuitInputs msgpack Buffer." );
241+ // arg[1]: logLevel number (required) - index into TS LogLevels array
242+ if (cb_info.Length () < 2 ) {
243+ throw Napi::TypeError::New (env,
244+ " Wrong number of arguments. Expected 2 arguments: AvmProvingInputs/AvmCircuitInputs "
245+ " msgpack Buffer and logLevel." );
229246 }
230247
231248 if (!cb_info[0 ].IsBuffer ()) {
232249 throw Napi::TypeError::New (
233250 env, " First argument must be a Buffer containing serialized AvmProvingInputs/AvmCircuitInputs" );
234251 }
235252
253+ if (!cb_info[1 ].IsNumber ()) {
254+ throw Napi::TypeError::New (env, " Second argument must be a log level number (0-7)" );
255+ }
256+
257+ // Extract log level and set logging flags
258+ int log_level = cb_info[1 ].As <Napi::Number>().Int32Value ();
259+ set_logging_from_level (log_level);
260+
236261 // Extract the inputs buffer
237262 auto inputs_buffer = cb_info[0 ].As <Napi::Buffer<uint8_t >>();
238263 size_t length = inputs_buffer.Length ();
0 commit comments