improves quality and reduces noise in logs

This commit is contained in:
jessop 2019-04-19 12:14:03 -04:00
parent b2e35c7e13
commit b2624026bb
9 changed files with 473 additions and 432 deletions

View file

@ -7,7 +7,6 @@ import Img from 'react-image';
const AssetPreview = ({ defaultThumbnail, claimData }) => { const AssetPreview = ({ defaultThumbnail, claimData }) => {
const {name, fileExt, contentType, thumbnail, title, blocked, transactionTime = 0} = claimData; const {name, fileExt, contentType, thumbnail, title, blocked, transactionTime = 0} = claimData;
const showUrl = createCanonicalLink({asset: {...claimData}}); const showUrl = createCanonicalLink({asset: {...claimData}});
console.log(transactionTime)
const embedUrl = `${showUrl}.${fileExt}`; const embedUrl = `${showUrl}.${fileExt}`;
const ago = Date.now() / 1000 - transactionTime; const ago = Date.now() / 1000 - transactionTime;
const dayInSeconds = 60 * 60 * 24; const dayInSeconds = 60 * 60 * 24;

816
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -21,7 +21,7 @@ const claimGet = async ({ ip, originalUrl, params, headers }, res) => {
try { try {
let claimInfo = await chainquery.claim.queries.resolveClaim(name, claimId).catch(() => {}); let claimInfo = await chainquery.claim.queries.resolveClaim(name, claimId).catch(() => {});
if (claimInfo) { if (claimInfo) {
logger.info('claim/get: claim resolved in chainquery'); logger.debug(`claim/get: claim resolved in chainquery`);
} }
if (!claimInfo) { if (!claimInfo) {
claimInfo = await db.Claim.resolveClaim(name, claimId); claimInfo = await db.Claim.resolveClaim(name, claimId);
@ -30,15 +30,15 @@ const claimGet = async ({ ip, originalUrl, params, headers }, res) => {
throw new Error('claim/get: resolveClaim: No matching uri found in Claim table'); throw new Error('claim/get: resolveClaim: No matching uri found in Claim table');
} }
if (headers && headers['user-agent'] && isBot(headers['user-agent'])) { if (headers && headers['user-agent'] && isBot(headers['user-agent'])) {
let lbrynetResolveResult = await resolveUri(`${name}#${claimId}`); logger.info(`Bot GetClaim: claimId: ${claimId}`);
const { message, completed } = lbrynetResolveResult;
res.status(200).json({ res.status(200).json({
success: true, success: true,
message, message: 'bot',
completed: false, completed: false,
}); });
return true; return true;
} }
logger.info(`GetClaim: ${claimId} UA: ${headers['user-agent']}`);
let lbrynetResult = await getClaim(`${name}#${claimId}`); let lbrynetResult = await getClaim(`${name}#${claimId}`);
if (!lbrynetResult) { if (!lbrynetResult) {
throw new Error(`claim/get: getClaim Unable to Get ${name}#${claimId}`); throw new Error(`claim/get: getClaim Unable to Get ${name}#${claimId}`);

View file

@ -141,12 +141,12 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
return publish(publishParams, fileName, fileType, filePath); return publish(publishParams, fileName, fileType, filePath);
}) })
.then(publishResults => { .then(publishResults => {
logger.info('Publish success >', publishResults); logger.debug('Publish success >', publishResults);
claimData = publishResults; claimData = publishResults;
({ claimId } = claimData); ({ claimId } = claimData);
if (channelName) { if (channelName) {
logger.info(`api/claim/publish: claimData.certificateId ${claimData.certificateId}`); logger.debug(`api/claim/publish: claimData.certificateId ${claimData.certificateId}`);
return chainquery.claim.queries.getShortClaimIdFromLongClaimId( return chainquery.claim.queries.getShortClaimIdFromLongClaimId(
claimData.certificateId, claimData.certificateId,
channelName channelName

View file

@ -1,8 +1,10 @@
const logger = require('winston'); const logger = require('winston');
const db = require('../../../../models'); const db = require('server/models');
const { publishClaim } = require('../../../../lbrynet'); const { publishClaim } = require('server/lbrynet');
const { createFileRecordDataAfterPublish } = require('../../../../models/utils/createFileRecordData.js'); const { createFileRecordDataAfterPublish } = require('server/models/utils/createFileRecordData.js');
const { createClaimRecordDataAfterPublish } = require('../../../../models/utils/createClaimRecordData.js'); const {
createClaimRecordDataAfterPublish,
} = require('server/models/utils/createClaimRecordData.js');
const deleteFile = require('./deleteFile.js'); const deleteFile = require('./deleteFile.js');
const publish = async (publishParams, fileName, fileType) => { const publish = async (publishParams, fileName, fileType) => {
@ -13,7 +15,7 @@ const publish = async (publishParams, fileName, fileType) => {
try { try {
publishResults = await publishClaim(publishParams); publishResults = await publishClaim(publishParams);
logger.info(`Successfully published ${publishParams.name} ${fileName}`, publishResults); logger.verbose(`Successfully published ${publishParams.name} ${fileName}`, publishResults);
const outpoint = `${publishResults.output.txid}:${publishResults.output.nout}`; const outpoint = `${publishResults.output.txid}:${publishResults.output.nout}`;
// get the channel information // get the channel information
if (publishParams.channel_name) { if (publishParams.channel_name) {
@ -29,39 +31,49 @@ const publish = async (publishParams, fileName, fileType) => {
const certificateId = channel ? channel.channelClaimId : null; const certificateId = channel ? channel.channelClaimId : null;
const channelName = channel ? channel.channelName : null; const channelName = channel ? channel.channelName : null;
const claimRecord = await createClaimRecordDataAfterPublish(certificateId, channelName, fileName, fileType, publishParams, publishResults); const claimRecord = await createClaimRecordDataAfterPublish(
const {claimId} = claimRecord; certificateId,
const upsertCriteria = {name: publishParams.name, claimId}; channelName,
fileName,
fileType,
publishParams,
publishResults
);
const { claimId } = claimRecord;
const upsertCriteria = { name: publishParams.name, claimId };
if (newFile) { if (newFile) {
// this is the problem // this is the problem
// //
fileRecord = await createFileRecordDataAfterPublish(fileName, fileType, publishParams, publishResults); fileRecord = await createFileRecordDataAfterPublish(
fileName,
fileType,
publishParams,
publishResults
);
} else { } else {
fileRecord = await db.File.findOne({where: {claimId}}).then(result => result.dataValues); fileRecord = await db.File.findOne({ where: { claimId } }).then(result => result.dataValues);
} }
const [file, claim] = await Promise.all([ const [file, claim] = await Promise.all([
db.upsert(db.File, fileRecord, upsertCriteria, 'File'), db.upsert(db.File, fileRecord, upsertCriteria, 'File'),
db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim'), db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim'),
]); ]);
logger.info(`File and Claim records successfully created (${publishParams.name})`); logger.debug(`File and Claim records successfully created (${publishParams.name})`);
await Promise.all([ await Promise.all([file.setClaim(claim), claim.setFile(file)]);
file.setClaim(claim), logger.debug(`File and Claim records successfully associated (${publishParams.name})`);
claim.setFile(file),
]);
logger.info(`File and Claim records successfully associated (${publishParams.name})`);
return Object.assign({}, claimRecord, {outpoint}); return Object.assign({}, claimRecord, { outpoint });
} catch (err) { } catch (err) {
// parse daemon response when err is a string // parse daemon response when err is a string
// this needs work // this needs work
logger.info('publish/publish err:', err); logger.error('publish/publish err:', err);
const error = typeof err === 'string' ? JSON.parse(err) : err; const error = typeof err === 'string' ? JSON.parse(err) : err;
if (publishParams.file_path) { if (publishParams.file_path) {
await deleteFile(publishParams.file_path); await deleteFile(publishParams.file_path);
} }
const message = error.error && error.error.message ? error.error.message : 'Unknown publish error'; const message =
error.error && error.error.message ? error.error.message : 'Unknown publish error';
return { return {
error: true, error: true,
message, message,

View file

@ -38,7 +38,7 @@ const rando = () => {
const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res) => { const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res) => {
// logging // logging
logger.info('Claim update request:', { logger.debug('Claim update request:', {
ip, ip,
headers, headers,
body, body,

View file

@ -388,7 +388,9 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.fetchClaim(name, claimId) this.fetchClaim(name, claimId)
.then(claim => { .then(claim => {
logger.info('resolveClaim claims:', claim); logger.debug(
`resolveClaim: ${name}, ${claimId}, -> certificateId: ${claim && claim.certificateId}`
);
if ( if (
serveOnlyApproved && serveOnlyApproved &&
!isApprovedChannel({ longId: claim.certificateId }, approvedChannels) !isApprovedChannel({ longId: claim.certificateId }, approvedChannels)

View file

@ -8,6 +8,7 @@ import createSagaMiddleware from 'redux-saga';
import { call } from 'redux-saga/effects'; import { call } from 'redux-saga/effects';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
import * as httpContext from 'express-http-context'; import * as httpContext from 'express-http-context';
import logger from 'winston';
import Reducers from '@reducers'; import Reducers from '@reducers';
import GAListener from '@components/GAListener'; import GAListener from '@components/GAListener';
@ -92,6 +93,7 @@ export default (req, res) => {
const preloadedState = store.getState(); const preloadedState = store.getState();
// send the rendered page back to the client // send the rendered page back to the client
res.send(renderFullPage(helmet, html, preloadedState)); res.send(renderFullPage(helmet, html, preloadedState));
}; };
@ -121,8 +123,8 @@ export default (req, res) => {
} }
if (canonicalUrl && canonicalUrl !== req.originalUrl) { if (canonicalUrl && canonicalUrl !== req.originalUrl) {
console.log(`redirecting ${req.originalUrl} to ${canonicalUrl}`); logger.verbose(`redirecting ${req.originalUrl} to ${canonicalUrl}`);
res.redirect(canonicalUrl); return res.redirect(canonicalUrl);
} }
return renderPage(store); return renderPage(store);

View file

@ -3,7 +3,7 @@ const logger = require('winston');
const config = require('@config/loggerConfig'); const config = require('@config/loggerConfig');
const { logLevel } = config; const { logLevel } = config;
function configureLogging () { function configureLogging() {
logger.info('configuring winston logger...'); logger.info('configuring winston logger...');
if (!config) { if (!config) {
return logger.warn('No logger config found'); return logger.warn('No logger config found');
@ -14,12 +14,12 @@ function configureLogging () {
// configure the winston logger // configure the winston logger
logger.configure({ logger.configure({
transports: [ transports: [
new (logger.transports.Console)({ new logger.transports.Console({
level : logLevel || 'debug', level: logLevel || 'debug',
timestamp : false, timestamp: true,
colorize : true, colorize: true,
prettyPrint : true, prettyPrint: true,
handleExceptions : true, handleExceptions: true,
humanReadableUnhandledException: true, humanReadableUnhandledException: true,
}), }),
], ],