Skip to content

Commit 1652b33

Browse files
petermetzkikoncuo
authored andcommitted
feat(core): add plugin registry log level constructor arg
Very minor improvement that makes it possible for the plugin registry to have an injectable log level for its logger (most classes already have this in the codebase but it was forgotten here). Signed-off-by: Peter Somogyvari <[email protected]>
1 parent f1abb3e commit 1652b33

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/cactus-core/src/main/typescript/plugin-registry.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { Optional } from "typescript-optional";
2+
import {
3+
Logger,
4+
LoggerProvider,
5+
LogLevelDesc,
6+
} from "@hyperledger/cactus-common";
27
import {
38
ICactusPlugin,
49
IPluginKeychain,
@@ -11,6 +16,7 @@ import {
1116
* the `PluginRegistry` class instances.
1217
*/
1318
export interface IPluginRegistryOptions {
19+
logLevel?: LogLevelDesc;
1420
plugins?: ICactusPlugin[];
1521
}
1622

@@ -23,7 +29,13 @@ export interface IPluginRegistryOptions {
2329
* classes in place of the interfaces currently describing the plugin architecture.
2430
*/
2531
export class PluginRegistry {
32+
public static readonly CLASS_NAME = "PluginRegistry";
2633
public readonly plugins: ICactusPlugin[];
34+
public readonly log: Logger;
35+
36+
public get className(): string {
37+
return PluginRegistry.CLASS_NAME;
38+
}
2739

2840
constructor(public readonly options: IPluginRegistryOptions = {}) {
2941
const fnTag = `PluginRegistry#constructor()`;
@@ -34,6 +46,11 @@ export class PluginRegistry {
3446
throw new TypeError(`${fnTag} options.plugins truthy but non-Array`);
3547
}
3648
this.plugins = options.plugins || [];
49+
50+
const level = this.options.logLevel || "INFO";
51+
const label = this.className;
52+
this.log = LoggerProvider.getOrCreate({ level, label });
53+
this.log.debug(`Instantiated ${this.className} OK`);
3754
}
3855

3956
public getPlugins(): ICactusPlugin[] {

0 commit comments

Comments
 (0)