Sha256: 0b762b04f93ad4295f08d2abe800ca63dec7f5c17624cf9e529dc42b903069a1

Contents?: true

Size: 1.34 KB

Versions: 26

Compression:

Stored size: 1.34 KB

Contents

var logLevel = "info";

function dummy() {}

function shouldLog(level) {
	var shouldLog =
		(logLevel === "info" && level === "info") ||
		(["info", "warning"].indexOf(logLevel) >= 0 && level === "warning") ||
		(["info", "warning", "error"].indexOf(logLevel) >= 0 && level === "error");
	return shouldLog;
}

function logGroup(logFn) {
	return function(level, msg) {
		if (shouldLog(level)) {
			logFn(msg);
		}
	};
}

module.exports = function(level, msg) {
	if (shouldLog(level)) {
		if (level === "info") {
			console.log(msg);
		} else if (level === "warning") {
			console.warn(msg);
		} else if (level === "error") {
			console.error(msg);
		}
	}
};

/* eslint-disable node/no-unsupported-features/node-builtins */
var group = console.group || dummy;
var groupCollapsed = console.groupCollapsed || dummy;
var groupEnd = console.groupEnd || dummy;
/* eslint-enable node/no-unsupported-features/node-builtins */

module.exports.group = logGroup(group);

module.exports.groupCollapsed = logGroup(groupCollapsed);

module.exports.groupEnd = logGroup(groupEnd);

module.exports.setLogLevel = function(level) {
	logLevel = level;
};

module.exports.formatError = function(err) {
	var message = err.message;
	var stack = err.stack;
	if (!stack) {
		return message;
	} else if (stack.indexOf(message) < 0) {
		return message + "\n" + stack;
	} else {
		return stack;
	}
};

Version data entries

26 entries across 25 versions & 8 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/webpack/hot/log.js
disco_app-0.18.0 test/dummy/node_modules/webpack/hot/log.js
disco_app-0.18.2 test/dummy/node_modules/webpack/hot/log.js
disco_app-0.16.1 test/dummy/node_modules/webpack/hot/log.js
disco_app-0.15.2 test/dummy/node_modules/webpack/hot/log.js
disco_app-0.18.4 test/dummy/node_modules/webpack/hot/log.js
disco_app-0.18.1 test/dummy/node_modules/webpack/hot/log.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/webpack/hot/log.js
disco_app-0.14.0 test/dummy/node_modules/webpack/hot/log.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/webpack/hot/log.js
tang-0.2.1 spec/tang_app/node_modules/webpack/hot/log.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/webpack/hot/log.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/webpack/hot/log.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/webpack/hot/log.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/webpack/hot/log.js
tang-0.2.0 spec/tang_app/node_modules/webpack/hot/log.js
tang-0.1.0 spec/tang_app/node_modules/webpack/hot/log.js
tang-0.0.9 spec/tang_app/node_modules/webpack/hot/log.js
enju_library-0.3.8 spec/dummy/node_modules/webpack/hot/log.js
jester-data-8.0.0 node_modules/webpack/hot/log.js