Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Import
var level = process.argv.indexOf('-d') === -1 ? 6 : 7;
var logger = require('caterpillar').createLogger({level:level});
var filter = require('caterpillar-filter').createFilter();
var human = require('caterpillar-human').createHuman();
// Where to output?
if ( process.title === 'browser' ) {
// Include the browser compatibility layer
var browser = require('caterpillar-browser').createBrowser();
// Pipe to filter to human to browser
logger.pipe(filter).pipe(human).pipe(browser);
}
else {
// Pipe to filter to human to stdout
logger.pipe(filter).pipe(human).pipe(process.stdout);
// If we are debugging, then write the original logger data to debug.log
const cli = require('commander')
// Import our package data for versioning
const { version } = require('../package.json')
// Import out projectz utility
const { Projectz } = require('./index.js')
// Prepare our logging configuration
const LOG_LEVEL_INFO = 6
const LOG_LEVEL_DEBUG = 7
const EXIT_ERROR_CODE = 1
const level = process.argv.includes('-d') ? LOG_LEVEL_DEBUG : LOG_LEVEL_INFO
// Setup our logging
const logger = new Logger({ level })
const filter = new Filter()
const human = new Human()
// Pipe logger output to filter, then filter output to stdout
logger
.pipe(filter)
.pipe(human)
.pipe(process.stdout)
// Extract out version out of our package and apply it to commander
cli.version(version)
// Define usage information
cli.usage(' [options]')
// Add our cwd customisation
// Import
var logger = require('caterpillar').createLogger();
var filter = require('./').createFilter({level:6}); // omit log level entries above 6
// Pipe logger output to filter, then filter output to stdout
logger.pipe(filter).pipe(process.stdout);
// Log
logger.log('info', 'this is the first log entry'); // info is level 6
logger.log('debug', 'this is the second log entry'); // debug is level 7, this will be omitted by our filter
logger.log('info', 'this is the third log entry'); // info is level 6
// Outputs
// {"args":["this is the first log entry"],"date":"2013-04-25T08:48:38.941Z","levelCode":6,"levelName":"info","line":"9","method":"Object.","file":"/Users/balupton/Projects/caterpillar-filter/example.js"}
// {"args":["this is the third log entry"],"date":"2013-04-25T08:48:38.948Z","levelCode":6,"levelName":"info","line":"11","method":"Object.","file":"/Users/balupton/Projects/caterpillar-filter/example.js"}
// Import
var logger = new require('caterpillar').createLogger();
var human = new require('./').createHuman();
// Pipe logger output to our human interface, then our human interface output to stdout
logger.pipe(human).pipe(process.stdout);
// Log
logger.log('warn', 'this is the first log entry');
// warn: this is the first log entry
logger.log('info', 'this is the second log entry');
// info: this is the second log entry
// Wait
setTimeout(function(){
// Set debug mode
logger.setConfig({level:7});
LogService.prototype.initialize = function () {
"use strict";
var logFilter, logHuman;
logHuman = human.createHuman();
//create the logger
this._logger = new Logger(this._settings.config);
if (this._settings.loggers.console.enabled) {
logFilter = filter.createFilter({level: (this._settings.loggers.console.debug ? 7 : 6)});
this._logger.pipe(logFilter).pipe(logHuman).pipe(process.stdout);
}
if (this._settings.loggers.file.enabled) {
if (!fs.existsSync(path.dirname(this._settings.loggers.file.filename))) {
fs.mkdirSync(path.dirname(this._settings.loggers.file.filename));
}
logFilter = filter.createFilter({level: (this._settings.loggers.file.debug ? 7 : 6)});
this._logger.pipe(logFilter).pipe(es.join('\n')).pipe(fs.createWriteStream(this._settings.loggers.file.filename, {flags: 'a'}));
}
};
if (err && docpad.getDebugging()) {
locale = docpad.getLocale();
return docpad.log('warn', locale.reportError + ' ' + locale.errorFollows, ((_ref2 = err.stack) != null ? _ref2 : err.message).toString());
}
});
this.trackRunnerInstance = new TaskGroup().run().on('complete', function(err) {
var locale, _ref2;
if (err && docpad.getDebugging()) {
locale = docpad.getLocale();
return docpad.log('warn', locale.trackError + ' ' + locale.errorFollows, ((_ref2 = err.stack) != null ? _ref2 : err.message).toString());
}
});
if ((loggers = instanceConfig.loggers)) {
delete instanceConfig.loggers;
} else {
logger = new (require('caterpillar').Logger)({
lineOffset: 2
});
loggerConsole = logger.pipe(new (require('caterpillar-filter').Filter)).pipe(new (require('caterpillar-human').Human));
loggers = {
logger: logger,
console: loggerConsole
};
}
safefs.unlink(this.debugLogPath, function() {});
this.setLoggers(loggers);
this.setLogLevel(this.initialConfig.logLevel);
this.on('log', function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return docpad.log.apply(this, args);
});
if (err && docpad.getDebugging()) {
locale = docpad.getLocale();
return docpad.log('warn', locale.reportError + ' ' + locale.errorFollows, ((_ref2 = err.stack) != null ? _ref2 : err.message).toString());
}
});
this.trackRunnerInstance = new TaskGroup().run().on('complete', function(err) {
var locale, _ref2;
if (err && docpad.getDebugging()) {
locale = docpad.getLocale();
return docpad.log('warn', locale.trackError + ' ' + locale.errorFollows, ((_ref2 = err.stack) != null ? _ref2 : err.message).toString());
}
});
if ((loggers = instanceConfig.loggers)) {
delete instanceConfig.loggers;
} else {
logger = new (require('caterpillar').Logger)({
lineOffset: 2
});
loggerConsole = logger.pipe(new (require('caterpillar-filter').Filter)).pipe(new (require('caterpillar-human').Human));
loggers = {
logger: logger,
console: loggerConsole
};
}
safefs.unlink(this.debugLogPath, function() {});
this.setLoggers(loggers);
this.setLogLevel(this.initialConfig.logLevel);
this.on('log', function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return docpad.log.apply(this, args);
});
seperator = '\n ';
debugString = "→ [" + entry.timestamp + "] [" + entry.file + ":" + entry.line + "] [" + entry.method + "]";
if (debugFormatter) {
debugString = debugFormatter(debugString);
}
result = "" + messageString + seperator + debugString + "\n";
} else {
result = messageString + '\n';
}
}
return result;
};
return Human;
})(require('caterpillar').Transform);
module.exports = {
Human: Human,
createHuman: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(Human, args, function(){});
}
};
}).call(this);
if (message) {
message = JSON.stringify(message);
}
return next(null, message);
};
Filter.prototype.format = function(entry) {
if (entry.levelNumber > this.config.level) {
return null;
}
return entry;
};
return Filter;
})(require('caterpillar').Transform);
module.exports = {
Filter: Filter,
createFilter: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(Filter, args, function(){});
}
};
seperator = '\n ';
debugString = "→ [" + entry.timestamp + "] [" + entry.file + ":" + entry.line + "] [" + entry.method + "]";
if (debugFormatter) {
debugString = debugFormatter(debugString);
}
result = "" + messageString + seperator + debugString + "\n";
} else {
result = messageString + '\n';
}
}
return result;
};
return Human;
})(require('caterpillar').Transform);
module.exports = {
Human: Human
};