Skip to content

Commit

Permalink
update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Jan 25, 2024
1 parent 4e31b52 commit 2349e16
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/chopsticks/src/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import { loadRpcPlugin, rpcPluginMethods } from '../plugins/index.js'

const rpcLogger = defaultLogger.child({ module: 'rpc' })
const rpcLogger = defaultLogger.child({ name: 'rpc' })

const allHandlers: Handlers = {
...substrate,
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const createServer = async (handler: Handler, port?: number) => {
result: resp ?? null,
}
} catch (e) {
logger.info('Error handling request: %s %o', e, (e as Error).stack)
logger.info('Error handling request: %o', (e as Error).stack)
return {
id: req.id,
jsonrpc: '2.0',
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/blockchain/block-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ export const buildBlock = async (
logger.info(
{
number: newBlockNumber,
extrinsicsCount: extrinsics.length,
extrinsics: extrinsics.map(truncate),
umpCount: Object.keys(ump).length,
},
`Try building block #${newBlockNumber.toLocaleString()}`,
`${await head.chain.api.getSystemChain()} building #${newBlockNumber.toLocaleString()}`,
)

let layer: StorageLayer | undefined
Expand Down Expand Up @@ -319,13 +319,13 @@ export const buildBlock = async (

logger.info(
{
number: newBlock.number,
number: finalBlock.number,
hash: finalBlock.hash,
extrinsics: truncate(includedExtrinsic),
pendingExtrinsicsCount: pendingExtrinsics.length,
pendingExtrinsics: pendingExtrinsics.map(truncate),
ump: truncate(ump),
},
'Block built',
`${await head.chain.api.getSystemChain()} new head #${finalBlock.number.toLocaleString()}`,
)

return [finalBlock, pendingExtrinsics]
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { pino } from 'pino'

export const pinoLogger = pino({
export const defaultLogger = pino({
level: (typeof process === 'object' && process.env.LOG_LEVEL) || 'info',
transport: {
target: 'pino-pretty',
options: {
ignore: 'pid,hostname',
hideObject: !!process.env.LOG_COMPACT,
},
},
})

export const defaultLogger = pinoLogger.child({ app: 'chopsticks' })

const innerTruncate =
(level = 0) =>
(val: any) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import _ from 'lodash'
import { decodeWellKnownKey } from './well-known-keys.js'
import { defaultLogger } from '../logger.js'

const logger = defaultLogger.child({ module: 'decoder' })
const logger = defaultLogger.child({ name: 'decoder' })

const _CACHE: LRUCache<Registry, LRUCache<HexString, StorageEntry>> = new LRUCache({ max: 20 /* max 20 registries */ })

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { HexString } from '@polkadot/util/types'
import { Keyring, createTestKeyring } from '@polkadot/keyring'
import { SubmittableExtrinsic } from '@polkadot/api-base/types'

const logger = defaultLogger.child({ module: 'utils' })
const logger = defaultLogger.child({ name: 'utils' })

export * from './signFake.js'

Expand Down

0 comments on commit 2349e16

Please sign in to comment.