-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new logger plugin to standardize how users can log information. This is a simple wrapper around consola for now and will be used later to make the logger configurable by the user in `apibara.config.ts`.
- Loading branch information
Showing
8 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@apibara-indexer-95c6848e-72aa-429f-bbe9-556a867c123e.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "Add logger plugin", | ||
"packageName": "@apibara/indexer", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "Add logger plugin", | ||
"packageName": "apibara", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { type ConsolaInstance, type ConsolaReporter, consola } from "consola"; | ||
import { useIndexerContext } from "../context"; | ||
import { defineIndexerPlugin } from "./config"; | ||
|
||
export type { ConsolaReporter, ConsolaInstance } from "consola"; | ||
|
||
export function logger<TFilter, TBlock, TTxnParams>({ | ||
logger, | ||
}: { logger?: ConsolaReporter } = {}) { | ||
return defineIndexerPlugin<TFilter, TBlock, TTxnParams>((indexer) => { | ||
indexer.hooks.hook("run:before", () => { | ||
const ctx = useIndexerContext(); | ||
|
||
if (logger) { | ||
ctx.logger = consola.create({ reporters: [logger] }); | ||
} else { | ||
ctx.logger = consola.create({}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function useLogger(): ConsolaInstance { | ||
const ctx = useIndexerContext(); | ||
|
||
if (!ctx?.logger) | ||
throw new Error("Logger plugin is not available in context"); | ||
|
||
return ctx.logger; | ||
} |