Improve logging

This commit is contained in:
Basti 2018-04-19 14:36:47 +02:00
parent aab5b58bab
commit 48a42d4f2c
3 changed files with 15 additions and 14 deletions

View File

@ -123,7 +123,7 @@ module.exports = async function(robot) {
// current block is the last mined one, thus we check from the next // current block is the last mined one, thus we check from the next
// mined one onwards to prevent getting previous events // mined one onwards to prevent getting previous events
let nextBlock = blockNumber + 1; let nextBlock = blockNumber + 1;
robot.logger.debug(`[kredits] watching events from block ${nextBlock} onward`); robot.logger.debug(`[hubot-kredits] Watching events from block ${nextBlock} onward`);
ethProvider.resetEventsBlock(nextBlock); ethProvider.resetEventsBlock(nextBlock);
Operator.on('ProposalCreated', handleProposalCreated); Operator.on('ProposalCreated', handleProposalCreated);
@ -133,7 +133,7 @@ module.exports = async function(robot) {
function handleProposalCreated(proposalId, creatorAccount, contributorId, amount) { function handleProposalCreated(proposalId, creatorAccount, contributorId, amount) {
Contributor.getById(contributorId).then((contributor) => { Contributor.getById(contributorId).then((contributor) => {
Operator.getById(proposalId).then((proposal) => { Operator.getById(proposalId).then((proposal) => {
console.debug('Proposal created:', proposal); robot.logger.debug(`[hubot-kredits] Proposal created (${proposal.description})`);
// messageRoom(`Let's give ${contributor.name} some kredits for ${proposal.url} (${proposal.description}): https://kredits.kosmos.org`); // messageRoom(`Let's give ${contributor.name} some kredits for ${proposal.url} (${proposal.description}): https://kredits.kosmos.org`);
}); });
}); });

View File

@ -3,7 +3,8 @@ const fetch = require('node-fetch');
module.exports = async function(robot, kredits) { module.exports = async function(robot, kredits) {
robot.logger.debug('[hubot-kredits] Loading GitHub integration...') robot.logger.debug('[hubot-kredits] Loading GitHub integration...');
const Contributor = kredits.Contributor; const Contributor = kredits.Contributor;
const Operator = kredits.Operator; const Operator = kredits.Operator;
@ -22,8 +23,9 @@ module.exports = async function(robot, kredits) {
} }
function createProposal(githubUser, amount, description, url, details) { function createProposal(githubUser, amount, description, url, details) {
return getContributorByGithubUser(githubUser).then((contributor) => { return getContributorByGithubUser(githubUser).then(contributor => {
robot.logger.debug(`[kredits] Creating proposal to issue ${amount}₭S to ${githubUser} for ${url}...`); robot.logger.debug(`[hubot-kredits] Creating proposal to issue ${amount}₭S to ${githubUser} for ${url}...`);
let contributionAttr = { let contributionAttr = {
contributorId: contributor.id, contributorId: contributor.id,
amount: amount, amount: amount,
@ -33,12 +35,11 @@ module.exports = async function(robot, kredits) {
details, details,
kind: 'dev' kind: 'dev'
}; };
return Operator.addProposal(contributionAttr).then((result) => {
robot.logger.debug('[kredits] proposal created:', util.inspect(result)); return Operator.addProposal(contributionAttr).catch(error => {
});
}).catch((error) => {
robot.logger.info(`[hubot-kredits] Error:`, error); robot.logger.info(`[hubot-kredits] Error:`, error);
messageRoom(`I wanted to propose giving kredits to ${githubUser} for ${url}, but I can't find their contact data. Please add them as a contributor: https://kredits.kosmos.org`); messageRoom(`I wanted to propose giving kredits to ${githubUser} for ${url}, but I cannot find their contact data. Please add them as a contributor: https://kredits.kosmos.org`);
});
}); });
} }

View File

@ -54,7 +54,7 @@ module.exports = async function(robot, kredits) {
} }
function analyzeUserChanges (user, changes) { function analyzeUserChanges (user, changes) {
robot.logger.info(`Analyzing ${changes.length} edits from ${user} ...`); robot.logger.debug(`Analyzing ${changes.length} edits from ${user} ...`);
const results = {}; const results = {};
results.pagesCreated = changes.filter(c => c.type === 'new'); results.pagesCreated = changes.filter(c => c.type === 'new');
@ -63,9 +63,9 @@ module.exports = async function(robot, kredits) {
.map(c => { return (c.oldlen < c.newlen) ? (c.newlen - c.oldlen) : 0; }) .map(c => { return (c.oldlen < c.newlen) ? (c.newlen - c.oldlen) : 0; })
.reduce((a, b) => a + b); .reduce((a, b) => a + b);
robot.logger.info(`Created ${results.pagesCreated.length} pages`); robot.logger.debug(`Created ${results.pagesCreated.length} pages`);
robot.logger.info(`Edited ${results.pagesChanged.length} pages`); robot.logger.debug(`Edited ${results.pagesChanged.length} pages`);
robot.logger.info(`Added ${results.linesAdded} lines of text\n`); robot.logger.debug(`Added ${results.linesAdded} lines of text\n`);
return results; return results;
} }