Skip to content

Commit 4a8e2ff

Browse files
committed
add per-plugin log level config
1 parent 23f9055 commit 4a8e2ff

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

ergomatic.example.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
logLevel: DEBUG
1+
logLevel: INFO
22
plugins:
33
- id: example_plugin
4+
logLevel: DEBUG # this is optional, will fallback to top-level `logLevel` value if not defined
45
enabled: true # defaults to true, can be set to false to disable plugin.
56
config:
67
tokenId: c7e22029868ecba3d43c385bb42b8a1c96d0114ad5261ec7e0d27a6f24254f92

plugins/example_plugin/mod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ExamplePlugin extends Plugin<ExamplePluginConfig> {
1818
}
1919

2020
async onStart(): Promise<void> {
21-
this.logger.info(
21+
this.logger.debug(
2222
`Example plugin started with config: ${JSON.stringify(this.config)}`,
2323
);
2424

src/config.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import { z } from "zod/mod.ts";
22
import merge from "lodash.merge";
33

4+
const logLevelSchema = z.enum([
5+
"NOTSET",
6+
"DEBUG",
7+
"INFO",
8+
"WARNING",
9+
"ERROR",
10+
"CRITICAL",
11+
]);
12+
413
const pluginConfigEntrySchema = z.object({
514
id: z.string(),
15+
logLevel: logLevelSchema.optional(),
616
enabled: z.boolean().default(true),
717
config: z.object({}).optional(),
818
});
919

1020
export type PluginConfigEntry = z.infer<typeof pluginConfigEntrySchema>;
1121

1222
const ergomaticConfigSchema = z.object({
13-
logLevel: z.enum(["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
23+
logLevel: logLevelSchema,
1424
node: z.object({
1525
endpoint: z.string().url(),
1626
}),

src/ergomatic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class Ergomatic extends Component<ErgomaticEvent> {
4949
return;
5050
}
5151

52-
this.logger.debug("Starting Ergomatic");
52+
this.logger.info("Starting Ergomatic");
5353

5454
const promises = this.#components.map(async (component) => {
5555
try {
@@ -73,7 +73,7 @@ export class Ergomatic extends Component<ErgomaticEvent> {
7373
return;
7474
}
7575

76-
this.logger.debug("Stopping Ergomatic");
76+
this.logger.info("Stopping Ergomatic");
7777

7878
const promises = this.#components.map(async (component) => {
7979
try {

src/plugins/plugin_manager.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,27 @@ export class PluginManager extends Component<PluginManagerEvent> {
108108
}
109109

110110
#createPlugin(
111-
config: ErgomaticConfig,
111+
ergomaticConfig: ErgomaticConfig,
112112
pluginEntry: PluginConfigEntry,
113113
): Plugin {
114-
const pluginCtor = this.#pluginConstructorMap[pluginEntry.id];
114+
const { id, logLevel } = pluginEntry;
115+
const pluginCtor = this.#pluginConstructorMap[id];
115116

116117
this.logger.debug(
117118
`Creating plugin from config: ${JSON.stringify(pluginEntry)}`,
118119
);
119120

120121
if (!pluginCtor) {
121-
throw new ErgomaticConfigError(`Unknown plugin ID: '${pluginEntry.id}'`);
122+
throw new ErgomaticConfigError(`Unknown plugin ID: '${id}'`);
122123
}
123124

124125
return new pluginCtor({
125126
config: pluginEntry.config,
126127
blockchainProvider: this.#blockchainProvider,
127-
logger: createLogger(pluginEntry.id, config.logLevel),
128+
logger: createLogger(
129+
pluginEntry.id,
130+
logLevel ?? ergomaticConfig.logLevel,
131+
),
128132
});
129133
}
130134

0 commit comments

Comments
 (0)