Use robot.logger instead of console logs

This commit is contained in:
Basti 2017-05-11 18:11:33 +02:00
parent 217219fc68
commit 98a3ee087b

View File

@ -16,6 +16,9 @@ const WalletSubprovider = require('ethereumjs-wallet/provider-engine');
const Web3Subprovider = require('web3-provider-engine/subproviders/web3.js');
const Web3 = require('web3');
(function() {
"use strict";
let engine = new ProviderEngine();
let walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
@ -40,20 +43,18 @@ web3.eth.defaultAccount = hubotWalletAddress;
let contracts = kreditsContracts(web3, config);
let kredits = contracts['Kredits'];
console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
module.exports = function(robot) {
(function() {
"use strict";
robot.logger.info('[hubot-kredits] Wallet address: ' + hubotWalletAddress);
web3.eth.getBalance(hubotWalletAddress, function (err, balance) {
if (err) { console.log('[HUBOT-KREDITS] Error checking balance'); return; }
if (err) { robot.logger.error('[hubot-kredits] Error checking balance'); return; }
if (balance <= 0) {
console.log('[HUBOT-KREDITS] Hubot is broke. Please send some ETH to ' + hubotWalletAddress);
robot.logger.info('[hubot-kredits] Hubot is broke. Please send some ETH to ' + hubotWalletAddress);
}
});
let getValueFromContract = function(contractMethod, ...args) {
console.log('[kredits] read from contract', contractMethod, ...args);
return new Promise((resolve, reject) => {
kredits[contractMethod](...args, (err, data) => {
if (err) { reject(err); }
@ -65,16 +66,16 @@ console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
let getContributorData = function(i) {
let promise = new Promise((resolve, reject) => {
getValueFromContract('contributorAddresses', i).then(address => {
console.log('address', address);
robot.logger.debug('address', address);
getValueFromContract('contributors', address).then(person => {
console.log('person', person);
robot.logger.debug('person', person);
let contributor = {
address: address,
github_username: person[1],
github_uid: person[0],
ipfsHash: person[2]
};
console.log('[kredits] contributor', contributor);
robot.logger.debug('[kredits] contributor', contributor);
resolve(contributor);
});
}).catch(err => reject(err));
@ -110,8 +111,6 @@ console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
return promise;
};
module.exports = function(robot) {
function messageRoom(message) {
robot.messageRoom(process.env.KREDITS_ROOM, message);
}
@ -142,7 +141,7 @@ console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
function createProposal(recipient, amount, url/*, metaData*/) {
return new Promise((resolve, reject) => {
// TODO write metaData to IPFS
console.log(`Creating proposal to issue ${amount}₭S to ${recipient} for ${url}...`);
robot.logger.debug(`Creating proposal to issue ${amount}₭S to ${recipient} for ${url}...`);
getContributorByGithubUser(recipient).then(c => {
kredits.addProposal(c.address, amount, url, '', (e/* , d */) => {
@ -221,7 +220,7 @@ console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
let evt = req.header('X-GitHub-Event');
let data = req.body;
console.log(`Received GitHub hook. Event: ${evt}, action: ${data.action}`);
robot.logger.debug(`Received GitHub hook. Event: ${evt}, action: ${data.action}`);
if (evt === 'pull_request' && data.action === 'closed') {
handleGitHubPullRequestClosed(data).then(() => res.send(200));