diff --git a/docs/Configuration.md b/docs/Configuration.md index b4067e8d2..f8c2709b7 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -11,7 +11,7 @@ The voting machine used by default by `Dao.new` when creating new DAOs. Default The location of a custom founders json configuration file, including the name of the file. The default points to `founders.json` located in arc.js/migrations which defines default founders for ganache. If the value is given as a relative path, then it must be relative to arc.js/dist/migrations. Refer here for [more about how to define founders](Migration). **logLevel** -The level of logging. Default is 9 (error | info). The available log levels, which may be combined, are: +The level of logging. Default is 9 (`LogLevel.error | LogLevel.info`). The available log levels, which may be combined, are: ``` none = 0 diff --git a/lib/configService.ts b/lib/configService.ts index 6f97be251..ac51bb15b 100644 --- a/lib/configService.ts +++ b/lib/configService.ts @@ -1,3 +1,5 @@ +import { PubSubEventService } from "./pubSubEventService"; + /** * get and set global Arc.js settings */ @@ -27,6 +29,7 @@ export class ConfigService { } } section[parts[count]] = value; + PubSubEventService.publish(`ConfigService.settingChanged.${setting}`, value); } constructor() { diff --git a/lib/index.ts b/lib/index.ts index 5042247f0..abe879d02 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -49,6 +49,7 @@ import { Web3 } from "web3"; import { AccountService } from "./accountService"; import { ConfigService } from "./configService"; import { LoggingService, LogLevel } from "./loggingService"; +import { PubSubEventService } from "./pubSubEventService"; import { Utils } from "./utils"; import { WrapperService, WrapperServiceInitializeOptions } from "./wrapperService"; @@ -76,6 +77,17 @@ export async function InitializeArcJs(options?: InitializeArcOptions): Promise { + LoggingService.logLevel = parseInt(value as any, 10) as LogLevel; + }); + if (options && options.useNetworkDefaultsFor) { const networkDefaults = ConfigService.get("networkDefaults")[options.useNetworkDefaultsFor]; if (!networkDefaults) { diff --git a/lib/loggingService.ts b/lib/loggingService.ts index 5c6eb4a15..dc9947705 100644 --- a/lib/loggingService.ts +++ b/lib/loggingService.ts @@ -1,5 +1,4 @@ import * as JSON from "circular-json"; -import { ConfigService } from "./configService"; export enum LogLevel { none = 0, @@ -67,7 +66,7 @@ export class LoggingService { public static loggers: Array = [new ConsoleLogger()]; - public static logLevel: LogLevel = parseInt(ConfigService.get("logLevel"), 10) as LogLevel; + public static logLevel: LogLevel = LogLevel.none; public static moduleName: string = "Arc.js"; diff --git a/test/utils.ts b/test/utils.ts index a0d2e6c3b..7ccfbfe24 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -25,6 +25,13 @@ describe("Misc", () => { assert.equal(setting, 10); }); + it("can update logLevel via config", async () => { + assert.equal(LoggingService.logLevel, 9); + ConfigService.set("logLevel", 5); + await helpers.sleep(50); + assert.equal(LoggingService.logLevel, 5); + }); + it("can check correct wrapper", async () => { const contractNameShouldBe = "GenesisProtocol"; const contractNameDontWant = "AbsoluteVote";