Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow dev rpc set runtime log level #390

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/chopsticks/src/plugins/set-runtime-log-level/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Handler, ResponseError } from '../../rpc/shared'
import { defaultLogger } from '../../logger'

export const rpc: Handler = async (context, [runtimeLogLevel]) => {
defaultLogger.debug({ runtimeLogLevel }, 'dev_setRuntimeLogLevel')

if (typeof runtimeLogLevel !== 'number') {
throw new ResponseError(1, `Invalid runtimeLogLevel ${runtimeLogLevel}`)
}

context.chain.runtimeLogLevel = runtimeLogLevel
}
13 changes: 11 additions & 2 deletions packages/core/src/blockchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Blockchain {
readonly db: DataSource | undefined
readonly mockSignatureHost: boolean
readonly allowUnresolvedImports: boolean
readonly runtimeLogLevel: number
#runtimeLogLevel: number
readonly registeredTypes: RegisteredTypes

readonly #txpool: TxPool
Expand Down Expand Up @@ -73,7 +73,7 @@ export class Blockchain {
this.db = db
this.mockSignatureHost = mockSignatureHost
this.allowUnresolvedImports = allowUnresolvedImports
this.runtimeLogLevel = runtimeLogLevel
this.#runtimeLogLevel = runtimeLogLevel
this.registeredTypes = registeredTypes

this.#head = new Block(this, header.number, header.hash)
Expand Down Expand Up @@ -109,6 +109,15 @@ export class Blockchain {
return this.#txpool
}

get runtimeLogLevel(): number {
return this.#runtimeLogLevel
}

set runtimeLogLevel(level: number) {
this.#runtimeLogLevel = level
logger.debug(`Runtime log level set to ${logger.level}`)
}

async saveBlockToDB(block: Block) {
if (this.db) {
const { hash, number, header, extrinsics } = block
Expand Down