Skip to content

Commit

Permalink
update logLevel on config changes (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkent600 authored Aug 10, 2018
1 parent b8d6a76 commit 4e2fdd7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/configService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PubSubEventService } from "./pubSubEventService";

/**
* get and set global Arc.js settings
*/
Expand Down Expand Up @@ -27,6 +29,7 @@ export class ConfigService {
}
}
section[parts[count]] = value;
PubSubEventService.publish(`ConfigService.settingChanged.${setting}`, value);
}

constructor() {
Expand Down
12 changes: 12 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -76,6 +77,17 @@ export async function InitializeArcJs(options?: InitializeArcOptions): Promise<W
LoggingService.info("Initializing Arc.js");
try {

/**
* Initialize LoggingService here to avoid cirular dependency involving ConfigService and PubSubService
*/
LoggingService.logLevel = parseInt(ConfigService.get("logLevel"), 10) as LogLevel;
/**
* Watch for changes in logLevel via ConfigService.
*/
PubSubEventService.subscribe(`ConfigService.settingChanged.logLevel`, (topics: string, value: number): void => {
LoggingService.logLevel = parseInt(value as any, 10) as LogLevel;
});

if (options && options.useNetworkDefaultsFor) {
const networkDefaults = ConfigService.get("networkDefaults")[options.useNetworkDefaultsFor];
if (!networkDefaults) {
Expand Down
3 changes: 1 addition & 2 deletions lib/loggingService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as JSON from "circular-json";
import { ConfigService } from "./configService";

export enum LogLevel {
none = 0,
Expand Down Expand Up @@ -67,7 +66,7 @@ export class LoggingService {

public static loggers: Array<ILogger> = [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";

Expand Down
7 changes: 7 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 4e2fdd7

Please sign in to comment.