Skip to content

Commit 0169fd7

Browse files
committed
refactor: make it more configurable
1 parent 34c6415 commit 0169fd7

File tree

11 files changed

+75
-30
lines changed

11 files changed

+75
-30
lines changed

apps/price_pusher/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ By default, the logging is set to `info`. You can change the logging level by pa
196196
The available levels are `error`, `warn`, `info`, `debug`, and `trace`. Also, the logs have JSON format. If you wish to run the code with
197197
human-readable logs, you can pipe the output of the program to `pino-pretty`. See the example below for more information on how to do this.
198198

199+
You can configure the log level of some of the modules of the price pusher as well. The available modules are PriceServiceConnection, which
200+
is responsible for connecting to the Hermes price service, and Controller, which is responsible for checking the prices from the Hermes
201+
and the on-chain Pyth contract and deciding whether to push a new price. You can configure the log level of these modules by passing the
202+
`--price-service-connection-log-level` and `--controller-log-level` arguments, respectively.
203+
199204
### Example
200205

201206
For example, to push `BTC/USD` and `BNB/USD` prices on Fantom testnet, run the following command:

apps/price_pusher/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"joi": "^17.6.0",
7272
"near-api-js": "^3.0.2",
7373
"pino": "^9.2.0",
74-
"ts-log": "^2.2.4",
7574
"web3": "^1.8.1",
7675
"web3-core": "^1.8.1",
7776
"web3-eth-contract": "^1.8.1",

apps/price_pusher/src/aptos/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export default {
3939
...options.pollingFrequency,
4040
...options.pushingFrequency,
4141
...options.logLevel,
42+
...options.priceServiceConnectionLogLevel,
43+
...options.controllerLogLevel,
4244
},
4345
handler: function (argv: any) {
4446
// FIXME: type checks for this
@@ -52,6 +54,8 @@ export default {
5254
pollingFrequency,
5355
overrideGasPriceMultiplier,
5456
logLevel,
57+
priceServiceConnectionLogLevel,
58+
controllerLogLevel,
5559
} = argv;
5660

5761
const logger = pino({ level: logLevel });
@@ -60,10 +64,9 @@ export default {
6064
const priceServiceConnection = new PriceServiceConnection(
6165
priceServiceEndpoint,
6266
{
63-
// Swtich to warn level if log level is info to reduce the noise
6467
logger: logger.child(
6568
{ module: "PriceServiceConnection" },
66-
{ level: logLevel === "info" ? "warn" : logLevel }
69+
{ level: priceServiceConnectionLogLevel }
6770
),
6871
}
6972
);
@@ -105,7 +108,7 @@ export default {
105108
pythListener,
106109
aptosListener,
107110
aptosPusher,
108-
logger.child({ module: "Controller" }),
111+
logger.child({ module: "Controller" }, { level: controllerLogLevel }),
109112
{ pushingFrequency }
110113
);
111114

apps/price_pusher/src/evm/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export default {
7474
...options.pollingFrequency,
7575
...options.pushingFrequency,
7676
...options.logLevel,
77+
...options.priceServiceConnectionLogLevel,
78+
...options.controllerLogLevel,
7779
},
7880
handler: function (argv: any) {
7981
// FIXME: type checks for this
@@ -92,6 +94,8 @@ export default {
9294
gasLimit,
9395
updateFeeMultiplier,
9496
logLevel,
97+
priceServiceConnectionLogLevel,
98+
controllerLogLevel,
9599
} = argv;
96100

97101
const logger = pino({ level: logLevel });
@@ -100,10 +104,9 @@ export default {
100104
const priceServiceConnection = new PriceServiceConnection(
101105
priceServiceEndpoint,
102106
{
103-
// Swtich to warn level if log level is info to reduce the noise
104107
logger: logger.child(
105108
{ module: "PriceServiceConnection" },
106-
{ level: logLevel === "info" ? "warn" : logLevel }
109+
{ level: priceServiceConnectionLogLevel }
107110
),
108111
}
109112
);
@@ -159,7 +162,7 @@ export default {
159162
pythListener,
160163
evmListener,
161164
evmPusher,
162-
logger.child({ module: "Controller" }),
165+
logger.child({ module: "Controller" }, { level: controllerLogLevel }),
163166
{ pushingFrequency }
164167
);
165168

apps/price_pusher/src/injective/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export default {
3737
...options.pollingFrequency,
3838
...options.pushingFrequency,
3939
...options.logLevel,
40+
...options.priceServiceConnectionLogLevel,
41+
...options.controllerLogLevel,
4042
},
4143
handler: function (argv: any) {
4244
// FIXME: type checks for this
@@ -51,6 +53,8 @@ export default {
5153
pollingFrequency,
5254
network,
5355
logLevel,
56+
priceServiceConnectionLogLevel,
57+
controllerLogLevel,
5458
} = argv;
5559

5660
const logger = pino({ level: logLevel });
@@ -63,10 +67,9 @@ export default {
6367
const priceServiceConnection = new PriceServiceConnection(
6468
priceServiceEndpoint,
6569
{
66-
// Swtich to warn level if log level is info to reduce the noise
6770
logger: logger.child(
6871
{ module: "PriceServiceConnection" },
69-
{ level: logLevel === "info" ? "warn" : logLevel }
72+
{ level: priceServiceConnectionLogLevel }
7073
),
7174
}
7275
);
@@ -106,7 +109,7 @@ export default {
106109
pythListener,
107110
injectiveListener,
108111
injectivePusher,
109-
logger.child({ module: "Controller" }),
112+
logger.child({ module: "Controller" }, { level: controllerLogLevel }),
110113
{ pushingFrequency }
111114
);
112115

apps/price_pusher/src/near/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default {
3838
...options.pollingFrequency,
3939
...options.pushingFrequency,
4040
...options.logLevel,
41+
...options.priceServiceConnectionLogLevel,
42+
...options.controllerLogLevel,
4143
},
4244
handler: function (argv: any) {
4345
// FIXME: type checks for this
@@ -52,6 +54,8 @@ export default {
5254
pushingFrequency,
5355
pollingFrequency,
5456
logLevel,
57+
priceServiceConnectionLogLevel,
58+
controllerLogLevel,
5559
} = argv;
5660

5761
const logger = pino({ level: logLevel });
@@ -60,10 +64,9 @@ export default {
6064
const priceServiceConnection = new PriceServiceConnection(
6165
priceServiceEndpoint,
6266
{
63-
// Swtich to warn level if log level is info to reduce the noise
6467
logger: logger.child(
6568
{ module: "PriceServiceConnection" },
66-
{ level: logLevel === "info" ? "warn" : logLevel }
69+
{ level: priceServiceConnectionLogLevel }
6770
),
6871
}
6972
);
@@ -104,7 +107,7 @@ export default {
104107
pythListener,
105108
nearListener,
106109
nearPusher,
107-
logger.child({ module: "Controller" }),
110+
logger.child({ module: "Controller" }, { level: controllerLogLevel }),
108111
{ pushingFrequency }
109112
);
110113

apps/price_pusher/src/options.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,23 @@ export const logLevel = {
6666
choices: ["trace", "debug", "info", "warn", "error"],
6767
} as Options,
6868
};
69+
70+
export const priceServiceConnectionLogLevel = {
71+
"price-service-connection-log-level": {
72+
description: "Log level for the price service connection.",
73+
type: "string",
74+
required: false,
75+
default: "warn",
76+
choices: ["trace", "debug", "info", "warn", "error"],
77+
} as Options,
78+
};
79+
80+
export const controllerLogLevel = {
81+
"controller-log-level": {
82+
description: "Log level for the controller.",
83+
type: "string",
84+
required: false,
85+
default: "info",
86+
choices: ["trace", "debug", "info", "warn", "error"],
87+
} as Options,
88+
};

apps/price_pusher/src/pyth-price-listener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
PriceServiceConnection,
55
} from "@pythnetwork/price-service-client";
66
import { PriceInfo, IPriceListener, PriceItem } from "./interface";
7-
import { Logger } from "ts-log";
7+
import { Logger } from "pino";
88

99
export class PythPriceListener implements IPriceListener {
1010
private connection: PriceServiceConnection;

apps/price_pusher/src/solana/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export default {
7272
...options.pollingFrequency,
7373
...options.pushingFrequency,
7474
...options.logLevel,
75+
...options.priceServiceConnectionLogLevel,
76+
...options.controllerLogLevel,
7577
},
7678
handler: function (argv: any) {
7779
const {
@@ -89,6 +91,8 @@ export default {
8991
jitoTipLamports,
9092
jitoBundleSize,
9193
logLevel,
94+
priceServiceConnectionLogLevel,
95+
controllerLogLevel,
9296
} = argv;
9397

9498
const logger = pino({ level: logLevel });
@@ -98,10 +102,9 @@ export default {
98102
const priceServiceConnection = new PriceServiceConnection(
99103
priceServiceEndpoint,
100104
{
101-
// Swtich to warn level if log level is info to reduce the noise
102105
logger: logger.child(
103106
{ module: "PriceServiceConnection" },
104-
{ level: logLevel === "info" ? "warn" : logLevel }
107+
{ level: priceServiceConnectionLogLevel }
105108
),
106109
}
107110
);
@@ -167,7 +170,7 @@ export default {
167170
pythListener,
168171
solanaPriceListener,
169172
solanaPricePusher,
170-
logger.child({ module: "Controller" }),
173+
logger.child({ module: "Controller" }, { level: controllerLogLevel }),
171174
{ pushingFrequency }
172175
);
173176

apps/price_pusher/src/sui/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export default {
7070
...options.pollingFrequency,
7171
...options.pushingFrequency,
7272
...options.logLevel,
73+
...options.priceServiceConnectionLogLevel,
74+
...options.controllerLogLevel,
7375
},
7476
handler: async function (argv: any) {
7577
const {
@@ -86,6 +88,8 @@ export default {
8688
gasBudget,
8789
accountIndex,
8890
logLevel,
91+
priceServiceConnectionLogLevel,
92+
controllerLogLevel,
8993
} = argv;
9094

9195
const logger = pino({ level: logLevel });
@@ -94,10 +98,9 @@ export default {
9498
const priceServiceConnection = new PriceServiceConnection(
9599
priceServiceEndpoint,
96100
{
97-
// Swtich to warn level if log level is info to reduce the noise
98101
logger: logger.child(
99102
{ module: "PriceServiceConnection" },
100-
{ level: logLevel === "info" ? "warn" : logLevel }
103+
{ level: priceServiceConnectionLogLevel }
101104
),
102105
priceFeedRequestConfig: {
103106
binary: true,
@@ -148,7 +151,7 @@ export default {
148151
pythListener,
149152
suiListener,
150153
suiPusher,
151-
logger.child({ module: "Controller" }),
154+
logger.child({ module: "Controller" }, { level: controllerLogLevel }),
152155
{ pushingFrequency }
153156
);
154157

0 commit comments

Comments
 (0)