Skip to content

Commit

Permalink
Pass through logger to agent so we actually get the logs (#184)
Browse files Browse the repository at this point in the history
* Pass through logger to agent so we actually get the logs

* Updating version to 0.10.26

---------

Co-authored-by: dc-autobot[bot] <181364585+dc-autobot[bot]@users.noreply.github.com>
  • Loading branch information
mattdean-digicatapult and dc-autobot[bot] authored Sep 26, 2024
1 parent 3f3786e commit ca70e1f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digicatapult/veritable-cloudagent",
"version": "0.10.25",
"version": "0.10.26",
"main": "build/index",
"type": "module",
"types": "build/index",
Expand Down Expand Up @@ -104,4 +104,4 @@
"overrides": {
"ref-napi": "npm:@2060.io/ref-napi"
}
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ container.register(PinoLogger, {
const agent = await setupAgent({
agentConfig: {
label: env.get('LABEL'),
logger: logger.child({ component: 'credo-ts-agent' }),
walletConfig: {
id: env.get('WALLET_ID'),
key: env.get('WALLET_KEY'),
Expand Down
25 changes: 16 additions & 9 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,30 @@ export default class PinoLogger extends BaseLogger {

// Map our log levels to tslog levels

public constructor(logLevel: LevelWithSilent) {
public constructor(logLevel: LevelWithSilent, logger?: Logger) {
super(tsLogLevelMap[logLevel])

this._logger = pino(
{
name: 'veritable-cloudagent',
timestamp: true,
level: logLevel,
},
process.stdout
)
this._logger =
logger ||
pino(
{
name: 'veritable-cloudagent',
timestamp: true,
level: logLevel,
},
process.stdout
)
}

public get logger() {
return this._logger
}

public child(bindings: pino.Bindings): PinoLogger {
const child = this._logger.child(bindings)
return new PinoLogger(invTsLogLevelMap[this.logLevel], child)
}

private log(level: Exclude<CredoLogLevel, CredoLogLevel.off>, message: string, data?: Record<string, any>): void {
const tsLogLevel = invTsLogLevelMap[level]
if (data) return this._logger[tsLogLevel]('%s %o', message, data)
Expand Down

0 comments on commit ca70e1f

Please sign in to comment.