Skip to content

Commit

Permalink
Added winston file transport and updated console.log usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Egyed committed Oct 11, 2020
1 parent a03ffde commit 2bdf07e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/network/web/coinbase/reporter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@


const crypto = require("crypto");
const nfetch = require("node-fetch");
const winston = require("winston");

const Oracle = require("../../../messaging/oracle");

Expand Down Expand Up @@ -61,8 +64,8 @@ class Reporter extends Oracle {
this._setStablecoins();
} catch (e) {
if (e instanceof nfetch.FetchError)
console.log("Coinbase fetch failed. Connection probably timed out");
else console.log("Coinbase fetch failed. Error converting to JSON");
winston.debug("Coinbase fetch failed. Connection probably timed out");
else winston.debug("Coinbase fetch failed. Error converting to JSON");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/network/webthree/providers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Web3 = require("web3");
const net = require("net");
const winston = require("winston");

const IPCProvider = path => {
return new Web3(path, net);
Expand Down Expand Up @@ -110,7 +111,7 @@ class MultiSendProvider {
try {
p.currentProvider.connection.destroy();
} catch {
console.log("Cannot close HTTP provider's connection");
winston.debug("Cannot close HTTP provider's connection");
}
}
});
Expand Down
13 changes: 12 additions & 1 deletion src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ winston.configure({
winston.format.simple()
),
transports: [
new winston.transports.Console({ handleExceptions: true }),
new winston.transports.Console({
handleExceptions: true,
level: "debug"
}),
new SlackHook({
level: "info",
webhookUrl: process.env.SLACK_WEBHOOK,
mrkdwn: true
}),
new winston.transports.File({
level: 'debug',
filename: `tmp/logs/nantucket.log`,
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
colorize: false,
})
],
exitOnError: false
Expand Down
2 changes: 1 addition & 1 deletion src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ for (let symbol in Tokens.mainnet) {
}

process.on("SIGINT", () => {
console.log("\nCaught interrupt signal");
winston.debug("\nCaught interrupt signal");

clearInterval(handle1);
clearInterval(handle2);
Expand Down
6 changes: 3 additions & 3 deletions src/start_txmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const Message = require("./messaging/message");
const Oracle = require("./messaging/oracle");

if (process.argv.length < 7) {
console.log("TxManager process requires config.json and 4 arguments");
winston.debug("TxManager process requires config.json and 4 arguments");
process.exit();
}
console.log(`TxManager ${process.pid} is running`);
winston.debug(`TxManager ${process.pid} is running`);

// src.network.webthree
const Wallet = require("./network/webthree/wallet");
Expand Down Expand Up @@ -65,6 +65,6 @@ process.on("SIGINT", code => {
}
txManager.stop();

console.log(`TxManager ${process.pid} has exited cleanly`);
winston.debug(`TxManager ${process.pid} has exited cleanly`);
process.exit();
});
6 changes: 3 additions & 3 deletions src/start_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const Message = require("./messaging/message");
const Oracle = require("./messaging/oracle");

if (process.argv.length < 7) {
console.log("Worker process requires config.json and 4 arguments");
winston.debug("Worker process requires config.json and 4 arguments");
process.exit();
}
console.log(`Worker ${process.pid} is running`);
winston.debug(`Worker ${process.pid} is running`);

const Worker = require("./worker");
const worker = new Worker(
Expand Down Expand Up @@ -52,6 +52,6 @@ process.on("SIGINT", code => {
}
worker.stop();

console.log(`Worker ${process.pid} has exited cleanly`);
winston.debug(`Worker ${process.pid} has exited cleanly`);
process.exit();
});
6 changes: 4 additions & 2 deletions src/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// src
import * as winston from "winston";

const Database = require("./database");
// src.messaging
const Candidate = require("./messaging/candidate");
Expand Down Expand Up @@ -133,11 +135,11 @@ class Worker extends Database {
}

_removeCandidate(address) {
console.log(`Removing candidate ${address}`);
winston.debug(`Removing candidate ${address}`);
for (let i = 0; i < this._candidates.length; i++) {
if (this._candidates[i].address !== address.toLowerCase()) continue;
this._candidates.splice(i, 1);
console.log(`Candidate ${address} was being watched`);
winston.debug(`Candidate ${address} was being watched`);
break;
}
}
Expand Down

0 comments on commit 2bdf07e

Please sign in to comment.