Node.js based forum software built for the modern web
get rid of some verbose logs, switch to ap.helpers.log
Barış Soner Uşaklı73eb0bffe714
diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.jsindex 27d243f72e..d1917d0901 100644--- a/src/activitypub/helpers.js+++ b/src/activitypub/helpers.js@@ -42,11 +42,11 @@ Helpers._test = (method, args) => {let _lastLog;Helpers.log = (message) => {if (!message) {- return _lastLog;+ return _lastLog || 'run in development mode to see last log';}- _lastLog = message;if (process.env.NODE_ENV === 'development') {+ _lastLog = message;winston.verbose(message);}};diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.jsindex ea0e99de35..d0ee3976a4 100644--- a/src/activitypub/inbox.js+++ b/src/activitypub/inbox.js@@ -449,7 +449,7 @@ inbox.announce = async (req) => {if (!fromRelay && !cid && !syncedCids.length) {const { followers } = await activitypub.actors.getLocalFollowCounts(actor);if (!followers) {- winston.verbose(`[activitypub/inbox.announce] Rejecting ${object.id} via ${actor} due to no followers`);+ activitypub.helpers.log(`[activitypub/inbox.announce] Rejecting ${object.id} via ${actor} due to no followers`);reject('Announce', object, actor);return;}@@ -635,7 +635,7 @@ inbox.undo = async (req) => {let { type: localType, id } = await helpers.resolveLocalId(object.object);- winston.verbose(`[activitypub/inbox/undo] ${type} ${localType && id ? `${localType} ${id}` : object.object} via ${actor}`);+ activitypub.helpers.log(`[activitypub/inbox/undo] ${type} ${localType && id ? `${localType} ${id}` : object.object} via ${actor}`);switch (type) {case 'Follow': {@@ -680,7 +680,7 @@ inbox.undo = async (req) => {const allowed = await privileges.posts.can('posts:upvote', id, activitypub._constants.uid);if (!allowed) {- winston.verbose(`[activitypub/inbox.like] ${id} not allowed to be upvoted.`);+ activitypub.helpers.log(`[activitypub/inbox.like] ${id} not allowed to be upvoted.`);reject('Like', object, actor);break;}diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex eb79dc282b..047edf9702 100644--- a/src/activitypub/index.js+++ b/src/activitypub/index.js@@ -338,9 +338,9 @@ ActivityPub.get = async (type, id, uri, options) => {});if (!String(response.statusCode).startsWith('2')) {- winston.verbose(`[activitypub/get] Received ${response.statusCode} when querying ${uri}`);+ ActivityPub.helpers.log(`[activitypub/get] Received ${response.statusCode} when querying ${uri}`);if (body.hasOwnProperty('error')) {- winston.verbose(`[activitypub/get] Error received: ${body.error}`);+ ActivityPub.helpers.log(`[activitypub/get] Error received: ${body.error}`);}const e = new Error(`[[error:activitypub.get-failed]]`);diff --git a/src/activitypub/notes.js b/src/activitypub/notes.jsindex ac5fda2894..8522965826 100644--- a/src/activitypub/notes.js+++ b/src/activitypub/notes.js@@ -318,7 +318,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {winston.warn(`[activitypub/notes.assert] Could not assert ${id} (${e.message}).`);return null;} finally {- winston.verbose(`[activitypub/notes.assert] Releasing lock (${id})`);+ activitypub.helpers.log(`[activitypub/notes.assert] Releasing lock (${id})`);await db.deleteObjectField('locks', id);}};@@ -563,7 +563,7 @@ Notes.getParentChain = async (uid, input) => {}}} catch (e) {- winston.verbose(`[activitypub/notes/getParentChain] Cannot retrieve ${id}, terminating here.`);+ activitypub.helpers.log(`[activitypub/notes/getParentChain] Cannot retrieve ${id}, terminating here.`);}}};diff --git a/src/categories/icon.js b/src/categories/icon.jsindex 7aa94ab802..8ce4da9253 100644--- a/src/categories/icon.js+++ b/src/categories/icon.js@@ -3,7 +3,6 @@const path = require('path');const fs = require('fs/promises');const nconf = require('nconf');-const winston = require('winston');const { default: satori } = require('satori');const sharp = require('sharp');@@ -33,14 +32,12 @@ Icons.get = async (cid) => {};Icons.flush = async (cid) => {- winston.verbose(`[categories/icons] Flushing ${cid}.`);const paths = Icons._constants.extensions.map(extension => path.resolve(nconf.get('upload_path'), 'category', `category-${cid}-icon.${extension}`));await Promise.all(paths.map((async path => await fs.rm(path, { force: true }))));};Icons.regenerate = async (cid) => {- winston.verbose(`[categories/icons] Regenerating ${cid}.`);const { icon, color, bgColor } = await categories.getCategoryData(cid);const fontPaths = new Map(Object.entries({diff --git a/src/posts/parse.js b/src/posts/parse.jsindex a4d8f57443..ae2bcb713e 100644--- a/src/posts/parse.js+++ b/src/posts/parse.js@@ -10,6 +10,7 @@ const plugins = require('../plugins');const translator = require('../translator');const utils = require('../utils');const postCache = require('./cache');+const devMode = process.env.NODE_ENV === 'development';let sanitizeConfig = {allowedTags: sanitize.defaults.allowedTags.concat([@@ -99,7 +100,9 @@ module.exports = function (Posts) {content.slice(current.index + offset + current[1].length);}} catch (err) {- winston.verbose(err.messsage);+ if (devMode) {+ winston.verbose(err.messsage);+ }}}current = regex.exec(content);