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 4 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
14 changes: 14 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,14 @@
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' || runtimeLogLevel < 0 || runtimeLogLevel > 5) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check the value, leave it to user to set correct value because it depends on runtime which value is correct

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making sure it's a number is enough

throw new ResponseError(1, `Invalid runtimeLogLevel ${runtimeLogLevel}`)
}

context.chain.runtimeLogLevel = runtimeLogLevel

defaultLogger.debug(`Runtime log level set to ${runtimeLogLevel}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the better place to log is in the setter

}
12 changes: 10 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,14 @@ export class Blockchain {
return this.#txpool
}

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

set runtimeLogLevel(level: number) {
this.#runtimeLogLevel = level
}

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