Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
Browse files Browse the repository at this point in the history
…to ethjs-repl
  • Loading branch information
scorbajio committed Dec 5, 2024
2 parents c11d573 + 100d77d commit 5a93f91
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/client/src/rpc/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export interface structLog {
}
error: boolean | undefined | null
}

const logLevels: { [key: number]: string } = {
0: 'error',
1: 'warn',
2: 'info',
3: 'debug',
}

/**
* Validate tracer opts to ensure only supports opts are provided
* @param opts a dictionary of {@link tracerOpts}
Expand Down Expand Up @@ -85,6 +93,7 @@ const validateTracerConfig = (opts: tracerOpts): tracerOpts => {
* @memberof module:rpc/modules
*/
export class Debug {
private client: EthereumClient
private service: FullEthereumService
private chain: Chain
private vm: VM
Expand All @@ -94,6 +103,7 @@ export class Debug {
* @param client Client to which the module binds
*/
constructor(client: EthereumClient, rpcDebug: boolean) {
this.client = client
this.service = client.service as FullEthereumService
this.chain = this.service.chain
this.vm = (this.service as FullEthereumService).execution?.vm
Expand Down Expand Up @@ -138,6 +148,9 @@ export class Debug {
1,
[[validators.hex]],
)
this.verbosity = middleware(callWithStackTrace(this.verbosity.bind(this), this._rpcDebug), 1, [
[validators.unsignedInteger],
])
}

/**
Expand Down Expand Up @@ -435,4 +448,13 @@ export class Debug {
const tx = block.transactions[txIndex]
return bytesToHex(tx.serialize())
}
/**
* Sets the verbosity level of the client logger
* @param level logger level to use with 0 as the lowest verbosity
*/
async verbosity(params: [number]) {
const [level] = params
this.client.config.logger.configure({ level: logLevels[level] })
return `level: ${this.client.config.logger.level}`
}
}
34 changes: 34 additions & 0 deletions packages/client/test/rpc/debug/verbosity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { assert, describe, it } from 'vitest'

import { createClient, createManager, getRPCClient, startRPC } from '../helpers.js'

const method = 'debug_verbosity'

const logLevels: { [key: number]: string } = {
0: 'error',
1: 'warn',
2: 'info',
3: 'debug',
}

describe(method, () => {
it('works', async () => {
const manager = createManager(await createClient({ opened: true, noPeers: true }))
const rpc = getRPCClient(startRPC(manager.getMethods()))
const client = manager['_client']

let res

// lowest level; e.g. only show errors
const levelError = 0
res = await rpc.request(method, [levelError])
assert.equal(res.result, 'level: error', 'verbosity level successfully lowered')
assert.equal(client.config.logger.level, logLevels[levelError])

// highest level; e.g. be very verbose and show even debug logs
const levelDebug = 3
res = await rpc.request(method, [levelDebug])
assert.equal(res.result, 'level: debug', 'verbosity level successfully increased')
assert.equal(client.config.logger.level, logLevels[levelDebug])
})
})

0 comments on commit 5a93f91

Please sign in to comment.