Add indentation groups & color escape sequences to cb & resolver logs

This commit is contained in:
Luca Hagel 2018-01-06 13:40:40 +01:00
parent 54149fb9e1
commit bdc05e1bc1
2 changed files with 37 additions and 33 deletions

View file

@ -4,7 +4,7 @@ Default list, single, and total resolvers
*/
import { Utils, debug } from 'meteor/vulcan:core';
import { Utils, debug, debugGroup, debugGroupEnd } from 'meteor/vulcan:core';
import { createError } from 'apollo-errors';
const defaultOptions = {
@ -24,10 +24,10 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
description: `A list of ${collectionName} documents matching a set of query terms`,
async resolver(root, { terms = {}, enableCache = false }, context, { cacheControl }) {
debug(`//--------------- start ${collectionName} list resolver ---------------//`);
debug(resolverOptions);
debug(terms);
debug('')
debugGroup(`--------------- start \x1b[35m${collectionName} list\x1b[0m resolver ---------------`);
debug(`Options: ${resolverOptions}`);
debug(`Terms: ${terms}`);
if (cacheControl && enableCache) {
const maxAge = resolverOptions.cacheMaxAge || defaultOptions.cacheMaxAge;
@ -57,8 +57,10 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
// prime the cache
restrictedDocs.forEach(doc => collection.loader.prime(doc._id, doc));
debug(`// ${restrictedDocs.length} documents returned`);
debug(`//--------------- end ${collectionName} list resolver ---------------//`);
debug(`\x1b[33m=> ${restrictedDocs.length} documents returned\x1b[0m`);
debugGroupEnd();
debug(`--------------- end \x1b[35m${collectionName} list\x1b[0m resolver ---------------`);
debug('')
// return results
return restrictedDocs;
@ -75,10 +77,10 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
description: `A single ${collectionName} document fetched by ID or slug`,
async resolver(root, { documentId, slug, enableCache = false }, context, { cacheControl }) {
debug(`//--------------- start ${collectionName} single resolver ---------------//`);
debug(resolverOptions);
debug(documentId);
debug('')
debugGroup(`--------------- start \x1b[35m${collectionName} single\x1b[0m resolver ---------------`);
debug(`Options: ${resolverOptions}`);
debug(`DocumentId: ${documentId}`);
if (cacheControl && enableCache) {
const maxAge = resolverOptions.cacheMaxAge || defaultOptions.cacheMaxAge;
@ -104,7 +106,9 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
const restrictedDoc = Users.restrictViewableFields(currentUser, collection, doc);
debug(`//--------------- end ${collectionName} single resolver ---------------//`);
debugGroupEnd();
debug(`--------------- end \x1b[35m${collectionName} single\x1b[0m resolver ---------------`);
debug('')
// filter out disallowed properties and return resulting document
return restrictedDoc;

View file

@ -73,7 +73,7 @@ export const runCallbacks = function () {
return callbacks.reduce(function (accumulator, callback) {
debug(`// Running callback [${callback.name}] on hook [${hook}]`);
debug(`\x1b[32m>> Running callback [${callback.name}] on hook [${hook}]\x1b[0m`);
const newArguments = [accumulator].concat(args);
@ -94,7 +94,7 @@ export const runCallbacks = function () {
}
} catch (error) {
console.log(`// error at callback [${callback.name}] in hook [${hook}]`);
console.log(`\x1b[31m// error at callback [${callback.name}] in hook [${hook}]\x1b[0m`);
console.log(error);
if (error.break || error.data && error.data.break) {
throw error;
@ -129,7 +129,7 @@ export const runCallbacksAsync = function () {
Meteor.defer(function () {
// run all post submit server callbacks on post object successively
callbacks.forEach(function (callback) {
debug(`// Running async callback [${callback.name}] on hook [${hook}]`);
debug(`\x1b[32m>> Running async callback [${callback.name}] on hook [${hook}]\x1b[0m`);
callback.apply(this, args);
});
});