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 1 commit
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
2 changes: 1 addition & 1 deletion scripts/data/gen-nodetime/src/relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
clockworkgr marked this conversation as resolved.
Show resolved Hide resolved

run([
["link", relayer.link.bind(relayer)],
Expand Down
28 changes: 21 additions & 7 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 @@ -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) {
clockworkgr marked this conversation as resolved.
Show resolved Hide resolved
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;
};
}
Expand Down
15 changes: 10 additions & 5 deletions scripts/data/gen-nodetime/src/relayer/lib/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -48,7 +52,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 @@ -65,7 +69,7 @@ export default class Relayer {

return path;
}

public async start([
path,
srcChain,
Expand All @@ -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(
Expand Down Expand Up @@ -127,7 +131,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 @@ -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));
}
}