From e75219005d9d7b2d734c1af4fd0c4a9be4f2d7c7 Mon Sep 17 00:00:00 2001 From: Clockwork Date: Thu, 17 Aug 2023 13:17:09 +0300 Subject: [PATCH 1/4] feat: Make relayer logging level configurable --- .../data/gen-nodetime/src/relayer/index.ts | 2 +- .../gen-nodetime/src/relayer/lib/logger.ts | 28 ++++++++++++++----- .../gen-nodetime/src/relayer/lib/relayer.ts | 15 ++++++---- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/scripts/data/gen-nodetime/src/relayer/index.ts b/scripts/data/gen-nodetime/src/relayer/index.ts index c7c7000620..984f068a3c 100644 --- a/scripts/data/gen-nodetime/src/relayer/index.ts +++ b/scripts/data/gen-nodetime/src/relayer/index.ts @@ -2,7 +2,7 @@ import run from "./jsonrpc"; import Relayer from "./lib/relayer"; -const relayer = new Relayer(); +const relayer = new Relayer(parseInt(process.argv[2])); run([ ["link", relayer.link.bind(relayer)], diff --git a/scripts/data/gen-nodetime/src/relayer/lib/logger.ts b/scripts/data/gen-nodetime/src/relayer/lib/logger.ts index 8f19bf92f7..f035216fcb 100644 --- a/scripts/data/gen-nodetime/src/relayer/lib/logger.ts +++ b/scripts/data/gen-nodetime/src/relayer/lib/logger.ts @@ -15,23 +15,37 @@ export default class ConsoleLogger { public readonly verbose: LogMethod; public readonly debug: LogMethod; - constructor() { - this.error = () => { + constructor(logLevel:number) { + this.error = (msg) => { + if(logLevel>=0) { + console.log(msg); + } return this; }; - this.warn = () => { + this.warn = (msg) => { + if(logLevel>=1) { + console.log(msg); + } return this; }; this.info = (msg) => { - if (msg.indexOf('Relay') == 0 && msg.indexOf('Relay 0') == -1) { - console.log(msg); + if(logLevel>=2) { + if (msg.indexOf('Relay') == 0 && msg.indexOf('Relay 0') == -1) { + console.log(msg); + } } return this; }; - this.verbose = () => { + this.verbose = (msg) => { + if(logLevel>=3) { + console.log(msg); + } return this; }; - this.debug = () => { + this.debug = (msg) => { + if(logLevel>=4) { + console.log(msg); + } return this; }; } diff --git a/scripts/data/gen-nodetime/src/relayer/lib/relayer.ts b/scripts/data/gen-nodetime/src/relayer/lib/relayer.ts index f97901d01e..0a04316e73 100644 --- a/scripts/data/gen-nodetime/src/relayer/lib/relayer.ts +++ b/scripts/data/gen-nodetime/src/relayer/lib/relayer.ts @@ -38,7 +38,11 @@ type PathEnd = { export default class Relayer { private defaultMaxAge = 86400; + private logLevel = 2; + constructor(logLevel: number=2) { + if (logLevel) this.logLevel=logLevel; + } public async link([ path, srcChain, @@ -48,7 +52,7 @@ export default class Relayer { ]: [Path, Chain, Chain, string, string]): Promise { const srcClient = await Relayer.getIBCClient(srcChain, srcKey); const dstClient = await Relayer.getIBCClient(dstChain, dstKey); - const link = await Relayer.create(srcClient, dstClient, srcChain.client_id, dstChain.client_id); + const link = await Relayer.create(srcClient, dstClient, srcChain.client_id, dstChain.client_id, this.logLevel); const channels = await link.createChannel( 'A', @@ -65,7 +69,7 @@ export default class Relayer { return path; } - + public async start([ path, srcChain, @@ -81,7 +85,7 @@ export default class Relayer { dstClient, path.src.connection_id, path.dst.connection_id, - new ConsoleLogger() + new ConsoleLogger(this.logLevel) ); const heights = await link.checkAndRelayPacketsAndAcks( @@ -127,7 +131,8 @@ export default class Relayer { nodeA: IbcClient, nodeB: IbcClient, clientA: string, - clientB: string + clientB: string, + logLevel:number ): Promise { let dstClientID = clientB; if (!clientB) { @@ -193,6 +198,6 @@ export default class Relayer { const endA = new Endpoint(nodeA, srcClientID, connIdA); const endB = new Endpoint(nodeB, dstClientID, connIdB); - return new Link(endA, endB, new ConsoleLogger()); + return new Link(endA, endB, new ConsoleLogger(logLevel)); } } From e44e3371fb79f63dab57028eb8f69a666eeeea3a Mon Sep 17 00:00:00 2001 From: Clockwork Date: Wed, 23 Aug 2023 11:43:28 +0300 Subject: [PATCH 2/4] fix: LogLevel constants --- scripts/data/gen-nodetime/src/relayer/index.ts | 4 +++- scripts/data/gen-nodetime/src/relayer/lib/logger.ts | 10 ++++++++-- scripts/data/gen-nodetime/src/relayer/lib/relayer.ts | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/data/gen-nodetime/src/relayer/index.ts b/scripts/data/gen-nodetime/src/relayer/index.ts index 984f068a3c..fbc98cffa2 100644 --- a/scripts/data/gen-nodetime/src/relayer/index.ts +++ b/scripts/data/gen-nodetime/src/relayer/index.ts @@ -1,8 +1,10 @@ import run from "./jsonrpc"; +import { LogLevels } from "./lib/logger"; import Relayer from "./lib/relayer"; -const relayer = new Relayer(parseInt(process.argv[2])); +const logLevel = parseInt(process.argv[2]); +const relayer = new Relayer(isNaN(logLevel) ? LogLevels.INFO: logLevel); run([ ["link", relayer.link.bind(relayer)], diff --git a/scripts/data/gen-nodetime/src/relayer/lib/logger.ts b/scripts/data/gen-nodetime/src/relayer/lib/logger.ts index f035216fcb..e0c757ff9b 100644 --- a/scripts/data/gen-nodetime/src/relayer/lib/logger.ts +++ b/scripts/data/gen-nodetime/src/relayer/lib/logger.ts @@ -7,7 +7,13 @@ interface Logger { verbose: LogMethod; debug: LogMethod; } - +export enum LogLevels { + ERROR = 0, + WARN = 1, + INFO = 2, + VERBOSE = 3, + DEBUG = 4 +} export default class ConsoleLogger { public readonly error: LogMethod; public readonly warn: LogMethod; @@ -15,7 +21,7 @@ export default class ConsoleLogger { public readonly verbose: LogMethod; public readonly debug: LogMethod; - constructor(logLevel:number) { + constructor(logLevel:LogLevels) { this.error = (msg) => { if(logLevel>=0) { console.log(msg); diff --git a/scripts/data/gen-nodetime/src/relayer/lib/relayer.ts b/scripts/data/gen-nodetime/src/relayer/lib/relayer.ts index 0a04316e73..7bb5bdba9c 100644 --- a/scripts/data/gen-nodetime/src/relayer/lib/relayer.ts +++ b/scripts/data/gen-nodetime/src/relayer/lib/relayer.ts @@ -8,7 +8,7 @@ import {buildCreateClientArgs, prepareConnectionHandshake} from "@confio/relayer import {orderFromJSON} from "@confio/relayer/build/codec/ibc/core/channel/v1/channel"; // local imports. -import ConsoleLogger from './logger'; +import ConsoleLogger, { LogLevels } from './logger'; type Chain = { id: string; @@ -40,7 +40,7 @@ export default class Relayer { private defaultMaxAge = 86400; private logLevel = 2; - constructor(logLevel: number=2) { + constructor(logLevel: LogLevels=LogLevels.INFO) { if (logLevel) this.logLevel=logLevel; } public async link([ From 2d3352f08155ddde3dabd5c974f78e421f4b5bff Mon Sep 17 00:00:00 2001 From: Clockwork Date: Wed, 23 Aug 2023 12:04:03 +0300 Subject: [PATCH 3/4] chore: Add changelog entry --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 4b682d0de0..2764186cbc 100644 --- a/changelog.md +++ b/changelog.md @@ -31,6 +31,7 @@ - [#3446](https://github.com/ignite/cli/pull/3446) Add `gas-adjustment` flag to the cosmos client. - [#3439](https://github.com/ignite/cli/pull/3439) Add `--build.tags` flag for `chain serve` and `chain build` commands. - [#3524](https://github.com/ignite/cli/pull/3524) Apply auto tools migration to other commands +- [#3636](https://github.com/ignite/cli/pull/3626) Add logging levels to relayer - Added compatibility check and auto migration features and interactive guidelines for the latest versions of the SDK ### Changes From e3c55dc2808358aa9d28dba5121de53638e0ed09 Mon Sep 17 00:00:00 2001 From: Clockwork Date: Mon, 18 Sep 2023 22:03:04 +0300 Subject: [PATCH 4/4] fix: address review --- scripts/data/gen-nodetime/src/relayer/lib/logger.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/data/gen-nodetime/src/relayer/lib/logger.ts b/scripts/data/gen-nodetime/src/relayer/lib/logger.ts index e0c757ff9b..00a966f12e 100644 --- a/scripts/data/gen-nodetime/src/relayer/lib/logger.ts +++ b/scripts/data/gen-nodetime/src/relayer/lib/logger.ts @@ -23,19 +23,19 @@ export default class ConsoleLogger { constructor(logLevel:LogLevels) { this.error = (msg) => { - if(logLevel>=0) { + if(logLevel>=LogLevels.ERROR) { console.log(msg); } return this; }; this.warn = (msg) => { - if(logLevel>=1) { + if(logLevel>=LogLevels.WARN) { console.log(msg); } return this; }; this.info = (msg) => { - if(logLevel>=2) { + if(logLevel>=LogLevels.INFO) { if (msg.indexOf('Relay') == 0 && msg.indexOf('Relay 0') == -1) { console.log(msg); } @@ -43,13 +43,13 @@ export default class ConsoleLogger { return this; }; this.verbose = (msg) => { - if(logLevel>=3) { + if(logLevel>=LogLevels.VERBOSE) { console.log(msg); } return this; }; this.debug = (msg) => { - if(logLevel>=4) { + if(logLevel>=LogLevels.DEBUG) { console.log(msg); } return this;