Skip to content

Commit

Permalink
chore: log levels and date formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mfw78 committed Sep 30, 2023
1 parent aa124cc commit fe6a0d9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
9 changes: 3 additions & 6 deletions src/domain/chainContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class ChainContext {
const currentTime = new Date().getTime();
const timeElapsed = currentTime - timeLastBlockProcessed;

log.trace(`diff: ${timeElapsed}ms`);
log.trace(`Time since last block processed: ${timeElapsed}ms`);

// If we haven't received a block in 30 seconds, exit so that the process manager can restart us
if (timeElapsed >= WATCHDOG_KILL_THRESHOLD) {
Expand Down Expand Up @@ -273,15 +273,12 @@ async function processBlock(
const receipt = await provider.getTransactionReceipt(event.transactionHash);
if (receipt) {
// run action
log.info(`Run "addContract" action for TX ${event.transactionHash}`);
log.info(`Running "addContract" action for TX ${event.transactionHash}`);
const result = await addContract(context, event)
.then(() => true)
.catch((e) => {
hasErrors = true;
log.error(
`[run_local] Error running "addContract" action for TX:`,
e
);
log.error(`Error running "addContract" action for TX:`, e);
return false;
});
log.info(
Expand Down
4 changes: 2 additions & 2 deletions src/domain/checkForAndPlaceOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function _checkForAndPlaceOrder(
lastHint?.result === PollResultCode.TRY_AT_EPOCH &&
blockTimestamp < lastHint.epoch
) {
log.info(
log.debug(
`Skipping conditional. Reason: Not due yet (TRY_AT_EPOCH=${
lastHint.epoch
}, ${formatEpoch(lastHint.epoch)}). ${logOrderDetails}`,
Expand All @@ -143,7 +143,7 @@ async function _checkForAndPlaceOrder(
lastHint?.result === PollResultCode.TRY_ON_BLOCK &&
blockNumber < lastHint.blockNumber
) {
log.info(
log.debug(
`Skipping conditional. Reason: Not due yet (TRY_ON_BLOCK=${
lastHint.blockNumber
}, in ${
Expand Down
12 changes: 7 additions & 5 deletions src/utils/logging.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as log from "loglevel";
import * as prefix from "loglevel-plugin-prefix";
import { Chalk } from "chalk";
import chalk = require("chalk");
import log from "loglevel";
import prefix from "loglevel-plugin-prefix";
import chalk, { Chalk } from "chalk";

const colors: Record<string, Chalk> = {
TRACE: chalk.magenta,
Expand All @@ -15,8 +14,11 @@ prefix.reg(log);
log.enableAll();

prefix.apply(log, {
timestampFormatter(date) {
return date.toISOString();
},
format(level, name, timestamp) {
return `${chalk.gray(`[${timestamp}]`)} ${colors[level.toUpperCase()](
return `${chalk.gray(timestamp)} ${colors[level.toUpperCase()](
level
)} ${chalk.green(`${name}:`)}`;
},
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"sourceMap": true,
"strict": true,
"target": "es2020",
"esModuleInterop": true,
"resolveJsonModule": true
},
// "exclude": ["**/*.spec.ts"],
Expand Down

0 comments on commit fe6a0d9

Please sign in to comment.