Skip to content

Commit

Permalink
feat(core): add plugin registry log level constructor arg
Browse files Browse the repository at this point in the history
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 <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz authored and kikoncuo committed Apr 13, 2021
1 parent f1abb3e commit 1652b33
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/cactus-core/src/main/typescript/plugin-registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Optional } from "typescript-optional";
import {
Logger,
LoggerProvider,
LogLevelDesc,
} from "@hyperledger/cactus-common";
import {
ICactusPlugin,
IPluginKeychain,
Expand All @@ -11,6 +16,7 @@ import {
* the `PluginRegistry` class instances.
*/
export interface IPluginRegistryOptions {
logLevel?: LogLevelDesc;
plugins?: ICactusPlugin[];
}

Expand All @@ -23,7 +29,13 @@ export interface IPluginRegistryOptions {
* classes in place of the interfaces currently describing the plugin architecture.
*/
export class PluginRegistry {
public static readonly CLASS_NAME = "PluginRegistry";
public readonly plugins: ICactusPlugin[];
public readonly log: Logger;

public get className(): string {
return PluginRegistry.CLASS_NAME;
}

constructor(public readonly options: IPluginRegistryOptions = {}) {
const fnTag = `PluginRegistry#constructor()`;
Expand All @@ -34,6 +46,11 @@ export class PluginRegistry {
throw new TypeError(`${fnTag} options.plugins truthy but non-Array`);
}
this.plugins = options.plugins || [];

const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
this.log.debug(`Instantiated ${this.className} OK`);
}

public getPlugins(): ICactusPlugin[] {
Expand Down

0 comments on commit 1652b33

Please sign in to comment.