Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make relayer logging level configurable #3626

Merged
merged 8 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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
Expand Down
4 changes: 3 additions & 1 deletion scripts/data/gen-nodetime/src/relayer/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import run from "./jsonrpc";
import { LogLevels } from "./lib/logger";

import Relayer from "./lib/relayer";

const relayer = new Relayer();
const logLevel = parseInt(process.argv[2]);
const relayer = new Relayer(isNaN(logLevel) ? LogLevels.INFO: logLevel);

run([
["link", relayer.link.bind(relayer)],
Expand Down
36 changes: 28 additions & 8 deletions scripts/data/gen-nodetime/src/relayer/lib/logger.ts
clockworkgr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,51 @@ 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;
public readonly info: LogMethod;
public readonly verbose: LogMethod;
public readonly debug: LogMethod;

constructor() {
this.error = () => {
constructor(logLevel:LogLevels) {
this.error = (msg) => {
if(logLevel>=LogLevels.ERROR) {
console.log(msg);
}
return this;
};
this.warn = () => {
this.warn = (msg) => {
if(logLevel>=LogLevels.WARN) {
console.log(msg);
}
return this;
};
this.info = (msg) => {
if (msg.indexOf('Relay') == 0 && msg.indexOf('Relay 0') == -1) {
console.log(msg);
if(logLevel>=LogLevels.INFO) {
if (msg.indexOf('Relay') == 0 && msg.indexOf('Relay 0') == -1) {
console.log(msg);
}
}
return this;
};
this.verbose = () => {
this.verbose = (msg) => {
if(logLevel>=LogLevels.VERBOSE) {
console.log(msg);
}
return this;
};
this.debug = () => {
this.debug = (msg) => {
if(logLevel>=LogLevels.DEBUG) {
console.log(msg);
}
return this;
};
}
Expand Down
17 changes: 11 additions & 6 deletions scripts/data/gen-nodetime/src/relayer/lib/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {buildCreateClientArgs, IbcClientOptions, prepareConnectionHandshake} fro
import {orderFromJSON} from "cosmjs-types/ibc/core/channel/v1/channel";

// local imports.
import ConsoleLogger from './logger';
import ConsoleLogger, { LogLevels } from './logger';

type Chain = {
id: string;
Expand Down Expand Up @@ -42,7 +42,11 @@ const defaultEstimatedIndexerTime = 80;

export default class Relayer {
private defaultMaxAge = 86400;
private logLevel = 2;

constructor(logLevel: LogLevels=LogLevels.INFO) {
if (logLevel) this.logLevel=logLevel;
}
public async link([
path,
srcChain,
Expand All @@ -52,7 +56,7 @@ export default class Relayer {
]: [Path, Chain, Chain, string, string]): Promise<Path> {
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',
Expand All @@ -69,7 +73,7 @@ export default class Relayer {

return path;
}

public async start([
path,
srcChain,
Expand All @@ -85,7 +89,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(
Expand Down Expand Up @@ -133,7 +137,8 @@ export default class Relayer {
nodeA: IbcClient,
nodeB: IbcClient,
clientA: string,
clientB: string
clientB: string,
logLevel:number
): Promise<Link> {
let dstClientID = clientB;
if (!clientB) {
Expand Down Expand Up @@ -199,6 +204,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));
}
}