lib/utils/logger.js
Function createLogger
has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring. Open
Open
const createLogger = (config, pairedDeviceContext) => {
/**
* Prefix log with device id
*/
function devicePrefix() {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function createLogger
has 180 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const createLogger = (config, pairedDeviceContext) => {
/**
* Prefix log with device id
*/
function devicePrefix() {
File logger.js
has 297 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
const colors = require('colors');
const logLevels = require('../constants/logLevels');
const jsonRenderer = require('prettyjson');
const {formatOpType} = require('./opType');
const timestamp = require('./timestamp');
Function getAppOutput
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
getAppOutput: (subtype, data) => {
// No need to display anything
if (config.logLevel === logLevels.silent) {
return;
}
Function args
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const args = data.map(d => {
// If not an array, display as it is.
if (!Array.isArray(d)) {
return d;
}
Function createDeviceLogger
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function createDeviceLogger() {
let logTime = 0;
// Create transform stream to prepend our custom prefix to each output new line.
const transformStream = new Transform({
Avoid too many return
statements within this function. Open
Open
return val1;
Avoid too many return
statements within this function. Open
Open
return subtype === 'time'
? `Timer '${val1}' already exists`
: `Timer '${val1}' does not exist`;
Avoid too many return
statements within this function. Open
Open
return `${val1}: ${val2}`;
Avoid too many return
statements within this function. Open
Open
return `${val1}: ${val2}ms`;
Avoid too many return
statements within this function. Open
Open
return `Count for '${val1}' does not exist`;
Avoid too many return
statements within this function. Open
Open
return val1.join('\n');