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

Added winston file transport and updated console.log usage #99

Closed
wants to merge 2 commits into from
Closed
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
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 @@

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the extra whitespace here?


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: `./logs/nantucket.log`,
handleExceptions: true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can multiple transports handle exceptions or will that break things?

json: true,
maxsize: 2242880, // ~2MB
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";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this import scheme work with current JS stuff?


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