Skip to content

566 logs #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7f4cba8
feat(utilities): Add info level log method
bmuenzenmeyer Oct 25, 2017
b934043
chore(checkConfiguration): Add configuration check for debug levels
bmuenzenmeyer Oct 25, 2017
e33eef8
feat(logs): Support escalating log levels, 'debug', 'info', 'warning'…
bmuenzenmeyer Oct 25, 2017
d729e4c
feat(debug): Remove printDebug entirely
bmuenzenmeyer Oct 25, 2017
d127296
feat(feat(logs): Rename utilities to log
bmuenzenmeyer Oct 25, 2017
2e821fe
feat(feat(logs): Rename utilities variable to logger
bmuenzenmeyer Oct 25, 2017
8cc61fd
chore(patternlab): Fix import
bmuenzenmeyer Oct 25, 2017
4ed5ac5
feat(logs): Refactor logs for annotation_exporter
bmuenzenmeyer Oct 25, 2017
5b7fdff
feat(logs): Refactor logs for asset_copy
bmuenzenmeyer Oct 25, 2017
2118e08
feat(logs): Refactor logs for lineage_hunter
bmuenzenmeyer Oct 25, 2017
4a681a4
fix(json_copy): Warn on error and rethrow to caller. They may be able…
bmuenzenmeyer Oct 25, 2017
9442658
feat(logs): Refactor logs for list_item_hunter
bmuenzenmeyer Oct 25, 2017
41a61c2
feat(logs): Refactor logs for markdown_parser
bmuenzenmeyer Oct 25, 2017
5021384
feat(logs): Refactor logs for parameter_hunter
bmuenzenmeyer Oct 25, 2017
85c039a
feat(logs): Refactor logs for pattern_assembler
bmuenzenmeyer Oct 25, 2017
eee7152
feat(logs): Refactor logs for json_copy
bmuenzenmeyer Oct 25, 2017
3881544
feat(logs): Refactor logs for pattern_engines
bmuenzenmeyer Oct 25, 2017
884975c
feat(logs): Refactor logs for plugin_manager
bmuenzenmeyer Oct 25, 2017
5442a84
feat(logs): Refactor logs for pseudopattern_hunter
bmuenzenmeyer Oct 25, 2017
c2a3fa6
feat(logs): Refactor logs for serve
bmuenzenmeyer Oct 25, 2017
9607018
feat(logs): Refactor logs for starterkit_manager
bmuenzenmeyer Oct 25, 2017
a57b7d1
feat(logs): Refactor logs for style_modifier_hunter
bmuenzenmeyer Oct 25, 2017
6bd0381
feat(logs): Refactor logs for ui_builder
bmuenzenmeyer Oct 25, 2017
f6a7e59
feat(logs): Refactor tests to account for debug
bmuenzenmeyer Oct 25, 2017
b3de4c6
feat(logs): Refactor logs for patternlab.js
bmuenzenmeyer Oct 25, 2017
2804d80
chore(pattern_engines): Remove newline
bmuenzenmeyer Oct 25, 2017
63fbede
fix(logs): Change to logLevel instead of debug
bmuenzenmeyer Oct 25, 2017
bbacfca
fix(logs): Change to logLevel instead of debug
bmuenzenmeyer Oct 25, 2017
f7e6f30
chore(logs): Missed a save
bmuenzenmeyer Oct 25, 2017
899dc01
chore(lint): Fix lint issues
bmuenzenmeyer Oct 25, 2017
0104deb
fix(logs): Change to logLevel instead of debug
bmuenzenmeyer Oct 25, 2017
fc75807
fix(logs): Trim up our logic
bmuenzenmeyer Oct 25, 2017
7316d37
fix(package): Use @pattern-lab npm org scoped live-server module
bmuenzenmeyer Oct 25, 2017
1a1ef62
chore(package): Update live-server dependency
bmuenzenmeyer Oct 25, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions core/lib/annotation_exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const glob = require('glob');
const fs = require('fs-extra');
const _ = require('lodash');
const mp = require('./markdown_parser');
const logger = require('./log');

const annotations_exporter = function (pl) {

Expand All @@ -18,9 +19,7 @@ const annotations_exporter = function (pl) {
try {
oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8');
} catch (ex) {
if (pl.config.debug) {
console.log('annotations.js file missing from ' + paths.source.annotations + '. This may be expected.');
}
logger.debug(`annotations.js file missing from ${paths.source.annotations}. This may be expected if you do not use annotations or are using markdown.`);
return [];
}

Expand All @@ -31,8 +30,7 @@ const annotations_exporter = function (pl) {
try {
var oldAnnotationsJSON = JSON.parse(oldAnnotations);
} catch (ex) {
console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js');
console.log(ex);
logger.error(`There was an error parsing JSON for ${paths.source.annotations}annotations.js`);
return [];
}
return oldAnnotationsJSON.comments;
Expand Down
18 changes: 6 additions & 12 deletions core/lib/asset_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const _ = require('lodash');
const path = require('path');
const process = require('process');
const logger = require('./log');

let copy = require('recursive-copy'); // eslint-disable-line prefer-const
let chokidar = require('chokidar'); // eslint-disable-line prefer-const
Expand Down Expand Up @@ -40,9 +41,7 @@ const asset_copier = () => {
dest,
options
).on(copy.events.COPY_FILE_COMPLETE, () => {
if (options.debug) {
console.log(`Moved ${p} to ${dest}`);
}
logger.debug(`Moved ${p} to ${dest}`);
options.emitter.emit('patternlab-asset-change', {
file: p,
dest: dest
Expand Down Expand Up @@ -70,9 +69,7 @@ const asset_copier = () => {

//if we want to watch files, do so, otherwise just copy each file
if (options.watch) {
if (patternlab.config.debug) {
console.log(`Pattern Lab is watching ${path.resolve(basePath, dir.source)} for changes`);
}
logger.info(`Pattern Lab is watching ${path.resolve(basePath, dir.source)} for changes`);

if (patternlab.watchers[key]) {
patternlab.watchers[key].close();
Expand Down Expand Up @@ -130,9 +127,7 @@ const asset_copier = () => {

_.each(globalPaths, (globalPath) => {

if (patternlab.config.debug) {
console.log(`Pattern Lab is watching ${globalPath} for changes`);
}
logger.info(`Pattern Lab is watching ${globalPath} for changes`);

if (patternlab.watchers[globalPath]) {
patternlab.watchers[globalPath].close();
Expand Down Expand Up @@ -180,9 +175,8 @@ const asset_copier = () => {
)
);
_.each(patternWatches, (patternWatchPath) => {
if (patternlab.config.debug) {
console.log(`Pattern Lab is watching ${patternWatchPath} for changes`);
}

logger.info(`Pattern Lab is watching ${patternWatchPath} for changes`);

const patternWatcher = chokidar.watch(
path.resolve(patternWatchPath),
Expand Down
6 changes: 3 additions & 3 deletions core/lib/json_copy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use strict";

const plutils = require('./utilities');
const logger = require('./log');
const json_copy = (data, callee) => {
try {
return JSON.parse(JSON.stringify(data));
} catch (e) {
//this is unlikely to be hit due to the passed in data already being loaded using JSON parsers
plutils.error(`JSON provided by ${callee} is invalid and cannot be copied`);
return {};
logger.warning(`JSON provided by ${callee} is invalid and cannot be copied`);
throw (e);
}
};

Expand Down
6 changes: 3 additions & 3 deletions core/lib/lineage_hunter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const extend = require("util")._extend;
const logger = require('./log');

const lineage_hunter = function () {

Expand Down Expand Up @@ -119,9 +120,8 @@ const lineage_hunter = function () {
const patternReverseStateIndex = patternStateCascade.indexOf(lineageRPattern.patternState);
if (lineageRPattern.patternState === '' || (patternStateIndex < patternReverseStateIndex)) {

if (patternlab.config.debug) {
console.log('Found a lower common denominator pattern state: ' + pattern.patternState + ' on ' + pattern.patternPartial + '. Setting reverse lineage pattern ' + lineageRPattern.patternPartial + ' from ' + (lineageRPattern.patternState === '' ? '<<blank>>' : lineageRPattern.patternState));
}
const oldState = lineageRPattern.patternState === '' ? '<<blank>>' : lineageRPattern.patternState;
logger.info(`Found a lower common denominator pattern state: ${pattern.patternState} on ${pattern.patternPartial}. Setting reverse lineage pattern ${lineageRPattern.patternPartial} from ${oldState}`);

lineageRPattern.patternState = pattern.patternState;

Expand Down
22 changes: 10 additions & 12 deletions core/lib/list_item_hunter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const list_item_hunter = function () {
const smh = require('./style_modifier_hunter');
const jsonCopy = require('./json_copy');
const Pattern = require('./object_factory').Pattern;
const logger = require('./log');

const pattern_assembler = new pa();
const style_modifier_hunter = new smh();
Expand All @@ -19,9 +20,7 @@ const list_item_hunter = function () {
if (matches !== null) {
matches.forEach(function (liMatch) {

if (patternlab.config.debug) {
console.log('found listItem of size ' + liMatch + ' inside ' + pattern.patternPartial);
}
logger.debug(`found listItem of size ${liMatch} inside ${pattern.patternPartial}`);

//find the boundaries of the block
const loopNumberString = liMatch.split('.')[1].split('}')[0].trim();
Expand All @@ -32,9 +31,8 @@ const list_item_hunter = function () {
const repeatedBlockTemplate = [];
let repeatedBlockHtml = '';
for (let i = 0; i < items.indexOf(loopNumberString); i++) {
if (patternlab.config.debug) {
console.log('list item(s) in pattern', pattern.patternPartial, 'adding', patternBlock, 'to repeatedBlockTemplate');
}

logger.debug(`list item(s) in pattern ${pattern.patternPartial}, adding ${patternBlock} to repeatedBlockTemplate`);
repeatedBlockTemplate.push(patternBlock);
}

Expand All @@ -43,8 +41,8 @@ const list_item_hunter = function () {
try {
listData = jsonCopy(patternlab.listitems, 'config.paths.source.data listitems');
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
logger.warning(`There was an error parsing JSON for ${pattern.relPath}`);
logger.warning(err);
}

listData = _.merge(listData, pattern.listitems);
Expand All @@ -64,8 +62,8 @@ const list_item_hunter = function () {
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
localData = jsonCopy(pattern.jsonFileData, `${pattern.patternPartial} data`);
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
logger.warning(`There was an error parsing JSON for ${pattern.relPath}`);
logger.warning(err);
}

let allData = _.merge(globalData, localData);
Expand All @@ -89,8 +87,8 @@ const list_item_hunter = function () {
cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partialName}`);
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
logger.warning(`There was an error parsing JSON for ${pattern.relPath}`);
logger.warning(err);
}

//if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #356
Expand Down
11 changes: 10 additions & 1 deletion core/lib/utilities.js → core/lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ const log = Object.assign({
*/
const debug = log.debug.bind(log);

/**
* @func info
* @desc Coloured info log
* @param {*} msg - The variadic messages to log out.
* @return {void}
*/
const info = log.info.bind(log);

/**
* @func warning
* @desc Coloured error log
* @desc Coloured warning log
* @param {*} e - The variadic messages to log out.
* @return {void}
*/
Expand Down Expand Up @@ -62,6 +70,7 @@ const reportError = function (message) {

module.exports = {
debug,
info,
warning,
error,
log,
Expand Down
5 changes: 3 additions & 2 deletions core/lib/markdown_parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const md = require('markdown-it')();
const yaml = require('js-yaml');
const logger = require('./log');

const markdown_parser = function () {

Expand Down Expand Up @@ -36,8 +37,8 @@ const markdown_parser = function () {
returnObject.markdown = md.render(block);
}
} catch (ex) {
console.log(ex);
console.log('error parsing markdown block', block);
logger.warning(ex);
logger.warning(`error parsing markdown block ${block}`);
return undefined;
}

Expand Down
19 changes: 7 additions & 12 deletions core/lib/parameter_hunter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const parameter_hunter = function () {
const smh = require('./style_modifier_hunter');
const style_modifier_hunter = new smh();
const pattern_assembler = new pa();
const logger = require('./log');

/**
* This function is really to accommodate the lax JSON-like syntax allowed by
Expand Down Expand Up @@ -49,10 +50,9 @@ const parameter_hunter = function () {
* * Return paramStringWellFormed.
*
* @param {string} pString
* @param {object} patternlab
* @returns {string} paramStringWellFormed
*/
function paramToJson(pString, patternlab) {
function paramToJson(pString) {
let colonPos = -1;
const keys = [];
let paramString = pString; // to not reassign param
Expand All @@ -67,10 +67,7 @@ const parameter_hunter = function () {
paramStringWellFormed = JSON.stringify(JSON.parse(pString));
return paramStringWellFormed;
} catch (err) {
//todo this might be a good candidate for a different log level, should we implement that someday
if (patternlab.config.debug) {
console.log(`Not valid JSON found for passed pattern parameter ${pString} will attempt to parse manually...`);
}
logger.debug(`Not valid JSON found for passed pattern parameter ${pString} will attempt to parse manually...`);
}

//replace all escaped double-quotes with escaped unicode
Expand Down Expand Up @@ -256,15 +253,13 @@ const parameter_hunter = function () {
//if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #190
partialPattern.extendedTemplate = partialPattern.template;

if (patternlab.config.debug) {
console.log('found patternParameters for ' + partialName);
}
logger.debug(`found patternParameters for ${partialName}`);

//strip out the additional data, convert string to JSON.
const leftParen = pMatch.indexOf('(');
const rightParen = pMatch.lastIndexOf(')');
const paramString = '{' + pMatch.substring(leftParen + 1, rightParen) + '}';
const paramStringWellFormed = paramToJson(paramString, patternlab);
const paramStringWellFormed = paramToJson(paramString);

let paramData = {};
let globalData = {};
Expand All @@ -275,8 +270,8 @@ const parameter_hunter = function () {
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
localData = jsonCopy(pattern.jsonFileData || {}, `pattern ${pattern.patternPartial} data`);
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
logger.warning(`There was an error parsing JSON for ${pattern.relPath}`);
logger.warning(err);
}

// resolve any pattern links that might be present
Expand Down
Loading