logger.dev = function(msg, data) {
		logger.log('info', msg, data);
	};
Beispiel #2
0
 debugObject: function (msg) {
   debugLogger.debug(formatMsg(msg));
 },
Beispiel #3
0
var app = require('express')(),
    winston = require('winston'),
    bodyParser = require('body-parser'),
    filter = require('./lib/filter');

/*
* Get winston to log uncaught exceptions and to not exit
*/
var logger = new winston.Logger({
  transports: [
    new winston.transports.Console({
      handleExceptions: true
    })
  ],
  exitOnError: false
});

app.use(bodyParser.json({limit: '1024kb'}));
app.use(bodyParser.text({type: 'text/*', limit: '1024kb'}));

app.get('/', function (req, res) {
    res.json({
        name: "Prepend", 
        description: "Prepends the posted data with the string supplied via prepend query param"
    });
});

app.post('/', function(req, res) {
    console.log(req.body);
    filter.prepend(req.body, req.param('prepend'), function (result) {
        if (result instanceof Object){
Beispiel #4
0
 infoObject: function (msg) {
   infoLogger.info(formatMsg(msg));
 },
Beispiel #5
0
 errorObject: function (msg) {
   errorLogger.error(formatMsg(msg));
 },
this.process.on('exit', code => logger.debug(`Child exited with code {${code}}`));
 this.process.stdout.on('error', (e) => {
     logger.debug(`Child process received error ${e}, sending kill signal`);
     this.kill(`Error reading from stdout: ${e}`);
 });
Beispiel #8
0
    loadExcelUsers: function(fileName) {
        logger.info('loadExcelUsers: Reading Excel file (',cfg.excelFilePath,")...");
        
        /* Open workbook containing users & attributes */
        var workbook = xlsx.readFile(cfg.excelFilePath);
        
        /* Convert contents of Excel Users & Attributes file to JavaScript object */
        var xlsxUsers = {};
        var xlsxAttrs = {};
        
        /* Sheet containing users must be named 'Users' or rename key below */
        var roa = xlsx.utils.sheet_to_row_object_array(workbook.Sheets['Users']);
        if (roa.length > 0){
            xlsxUsers = roa;
            logger.info('loadExcelUsers: ', roa.length, 'Users loaded.')
        } else {
            logger.error('loadExcelUsers: No data found in Users worksheet!');
        }
        
        /* Sheet containing attributes must be named 'Attributes' or rename key below */
        var roa = xlsx.utils.sheet_to_row_object_array(workbook.Sheets['Attributes']);
        if (roa.length > 0){
            xlsxAttrs = roa;
            logger.info('loadExcelUsers: ', roa.length, 'Attributes loaded.')
        } else {
            logger.error('loadExcelUsers: No data found in Attributes worksheet!');
        }
        
        /* Create empty objects to populated from xlsx content */
        var Users = {};
        logger.debug('loadExcelUsers: Converting Excel data into JavaScript object...');
                
        /* Transform xlsx data into JavaScript object used by templating engine to render user list */
        for (var key in xlsxUsers) {            
            
            var User = {};
                    
            if (xlsxUsers.hasOwnProperty(key)) {
                var uid = xlsxUsers[key].userid;
                var name = xlsxUsers[key].name;
                
                logger.info('loadExcelUsers: Transforming user (',name,')...');
                
                User["userid"] = uid;
                User["name"] = name;
                
                Users[key]=User;
                
                var userSpecificAttrs = xlsxAttrs.filter( function(item){return (item.userid==uid);} );
                logger.info('loadExcelUsers: Found ',userSpecificAttrs.length,' attributes associated with user (',name,')');
            
                var userGroups = [];
                var userApps = [];
                
                for(var i=0; i<userSpecificAttrs.length; i++) {
                    logger.info('loadExcelUsers: Transforming attribute (',userSpecificAttrs[i].type,') with value (',userSpecificAttrs[i].value,')...');
                    if (userSpecificAttrs[i].type == 'group') {
                        userGroups.push(userSpecificAttrs[i].value);
                    } else if (userSpecificAttrs[i].type == 'image') {
                        User["image"]=userSpecificAttrs[i].value;
                    } else if (userSpecificAttrs[i].type == 'app') {
                        userApps.push(userSpecificAttrs[i].value);
                    } else if (userSpecificAttrs[i].type == 'udc') {
                        User["udc"] = userSpecificAttrs[i].value;
                    } else if (userSpecificAttrs[i].type == 'title') {
                        User["title"] = userSpecificAttrs[i].value;
                    } else if (userSpecificAttrs[i].type == 'role') {
                        User["role"] = userSpecificAttrs[i].value;
                    } else {
                        logger.info('loadExcelUsers: Unrecognized attribute encountered (',userSpecificAttrs[i].type,') and ignored.');    
                    }                     
                }
                
                User["groups"] = userGroups;    
                User["apps"] = userApps;                                            
            }
        }
        logger.info('loadExcelUsers: JavaScript object creation complete.');
        
        var config = {};
        config.users = Users;
        logger.info('loadExcelUsers: Javascript object dump:\n',config);
	    return config;
      
    }
Beispiel #9
0
export default function (opts) {
  const logger = new Logger()
  logger.add(winston.transports.File, opts)
  return logger.info.bind(logger)
}
 promise.then((version) => {
         log.info('success');
         process.exit();
     })
 .catch((err) => {
     log.error(err);
     process.exit(1);
 });
	logger.data = function(data) {
		logger.log('data', data);
	};
	logger.res = function(msg, data) {
		logger.log('response', msg, data);
	};
	logger.req = function(url, data) {
		logger.log('request', msg, data);
	};
    /**
     * Creates a new instance of Phantom
     *
     * @param args command args to pass to phantom process
     * @param [config] configuration object
     * @param [config.phantomPath] path to phantomjs executable
     */
    constructor(args = [], config = {}) {
        if (!Array.isArray(args)) {
            throw new Error('Unexpected type of parameters. Expecting args to be array.');
        }
        if (!config || typeof config !== 'object') {
            throw new Error('Unexpected type of parameters. Expecting config to be object.');
        }

        let phantomPath = typeof config.phantomPath === 'string' ? config.phantomPath : phantomjs.path;

        if (phantomPath === null) {
            throw new Error(`PhantomJS binary was not found. This generally means something went wrong when installing phantomjs-prebuilt. Exiting.`);
        }

        let pathToShim = path.normalize(__dirname + '/shim.js');
        logger.debug(`Starting ${phantomPath} ${args.concat([pathToShim]).join(' ')}`);

        this.process = spawn(phantomPath, args.concat([pathToShim]));
        this.process.stdin.setEncoding('utf-8');

        this.commands = new Map();
        this.events = new Map();

        this.process.stdout.pipe(new Linerstream()).on('data', data => {
            const message = data.toString('utf8');
            if (message[0] === '>') {
                let json = message.substr(1);
                logger.debug('Parsing: %s', json);
                const command = JSON.parse(json);

                let deferred = this.commands.get(command.id).deferred;
                if (command.error === undefined) {
                    deferred.resolve(command.response);
                } else {
                    deferred.reject(new Error(command.error));
                }
                this.commands.delete(command.id);
            } else if (message.indexOf('<event>') === 0) {
                let json = message.substr(7);
                logger.debug('Parsing: %s', json);
                const event = JSON.parse(json);

                var emitter = this.events[event.target];
                if (emitter) {
                    emitter.emit.apply(emitter, [event.type].concat(event.args));
                }
            } else {
                logger.info(message);
            }
        });


        this.process.stderr.on('data', data => logger.error(data.toString('utf8')));
        this.process.on('exit', code => logger.debug(`Child exited with code {${code}}`));
        this.process.on('error', error => {
            logger.error(`Could not spawn [${phantomPath}] executable. Please make sure phantomjs is installed correctly.`);
            logger.error(error);
            this.kill(`Process got an error: ${error}`);
            process.exit(1);
        });

        this.process.stdin.on('error', (e) => {
            logger.debug(`Child process received error ${e}, sending kill signal`);
            this.kill(`Error reading from stdin: ${e}`);
        });

        this.process.stdout.on('error', (e) => {
            logger.debug(`Child process received error ${e}, sending kill signal`);
            this.kill(`Error reading from stdout: ${e}`);
        });

        this.heartBeatId = setInterval(this._heartBeat.bind(this), 100);
    }
Beispiel #16
0
}

// Set up our options
var options = {
  	"transports" : [
      // Defaults to logging to a console.
  		new (winston.transports.Console)({ "colorize" : true, "level" : "silly", "silent" : false, "timestamp" : true, "json":false,"prettyPrint" : true})
  	]
  };
if(config.environment == "production"){
  options.exitOnError = false;
  options.exceptionHandlers = [new (winston.transports.Console)({ "colorize" : true, "level" : "info", "silent" : false, "timestamp" : true, "json":false,"prettyPrint" : true})];
}

// Create the winston instance
var logger = new (winston.Logger)(options);

// Add-Ons
// -------

// **Log Files**
// If config.logFiles is true, we'll log to files.
if(config.logFiles){
  logger.add(winston.transports.File,{ "filename" : log_folder + "/log.log", "timestamp" : true, "level" : "info", "json":false,"prettyPrint" : true });
  logger.handleExceptions(new (winston.transports.File)({ "filename": log_folder + "/exceptions.log", "timestamp" : true, "json":false,"prettyPrint" : true }));
}

// **Amazon SNS notifications**
// If provided, this will use amazon sns to notify you if the proxy hits an uncaught exception.

// require some config stuff
this.process.stderr.on('data', data => logger.error(data.toString('utf8')));
Beispiel #18
0
const winston = require('winston');
const { env: { LOGENTRIES_TOKEN: logentriesToken, NODE_ENV: environment = 'production' } } = process;
const development = environment === 'development';
const test = environment === 'test';
const logger = new winston.Logger();
require('le_node');

if (!development && !test && logentriesToken) {
    winston.exitOnError = false;
    logger.add(winston.transports.Logentries, { token: logentriesToken, withStack: true, secure: true });
} else if (!test) {
    logger.add(winston.transports.Console, {}, false);
}

logger.write = logger.info;

module.exports = logger;
 this.process.on('error', error => {
     logger.error(`Could not spawn [${phantomPath}] executable. Please make sure phantomjs is installed correctly.`);
     logger.error(error);
     this.kill(`Process got an error: ${error}`);
     process.exit(1);
 });
Beispiel #20
0
// Implements the Database Fetch component of the clock metrology project
// Created by D & D Kirkby, Dec 2013

var winston_module = require('winston');

var connectToDB = require('./dbConnection').connectToDB;
var bins = require('./bins');

// Tracks the date of the first boot packet
var latestDate = null;

// Log to file
var winston = new (winston_module.Logger)({
	transports: [
		new (winston_module.transports.Console)({ level: 'warn' }),
		new (winston_module.transports.File)({ filename: 'ticktock.log', level: 'verbose' })
	]
});

// Parses command-line arguments.
var noSerial = false;
var noDatabase = false;
var debug = false;
var pythonFlags = ["--load-template", "template2048.dat"];
process.argv.forEach(function(val,index,array) {
	if(val == '--no-serial') noSerial = true;
	else if(val == '--no-database') noDatabase = true;
	else if(val == '--debug') {
		winston.transports.console.level = 'debug';
		winston.transports.file.level = 'debug';
		debug = true;
Beispiel #21
0
var config = require('./config');
var winston = require('winston');
var papertrail = require('winston-papertrail');

var logger = new (winston.Logger)({
  transports: [
    new (winston.transports.Console)({level: 'debug'})
  ]
});

logger.cli();

if (config.papertrail.port) {
  logger.add(papertrail.Papertrail, {
    host: config.papertrail.host,
    port: config.papertrail.port,
  });
}
else {
  logger.debug('No papertrail token');
}

module.exports = logger;
Beispiel #22
0
function gracefulExit()
{
	winston.info("Stopping Fetch");
}
Beispiel #23
0
 warnObject: function (msg) {
   infoLogger.warn(formatMsg(msg));
 },
Beispiel #24
0
	process.on('message', function(message) {
		winston.verbose("Starting Fetch");
		fetch(message.query, config.dataPacketModel, config.bootPacketModel, config.averageDataModel, config.gpsStatusModel, config.rawDataModel);
	});
Beispiel #25
0
 statsObject: function (msg) {
   statsLogger.info(formatMsg(msg));
 },
Beispiel #26
0
// Responds to a request to fetch data.
function fetch(query, dataPacketModel, bootPacketModel, averageDataModel, gpsStatusModel, rawDataModel) {
	// Gets the date range to fetch.
	var from = ('from' in query) ? query.from : '-120';
	var to = ('to' in query) ? query.to : 'now';
	var mostRecent = false;

	// Tries to interpret to as a date string
	to = new Date(Date.parse(to));
	// NB: Hardcoded 16 Second GPS-UTC Offset
	var utcNow = new Date();
	var GPS_UTC_OFFSET = 16;
	if(to == 'Invalid Date') to = new Date(utcNow.getTime()+GPS_UTC_OFFSET*1000);

	// Tries to interpret from as start keyword
	if(from == 'start' && latestDate !== null){
		from = latestDate;
	// Tries to interpret from as "the most recent sample in the database"
	} else if(from == '-1') {
		mostRecent = true;
	// Tries to interpret from as a date string
	} else {
		from = new Date(Date.parse(from));
		if(from == 'Invalid Date') {
			// Defaults to fetching DEFAULT_FETCH seconds.
			from = new Date(to.getTime() - DEFAULT_FETCH*1000);
		}
	}
	winston.verbose('query', query);
	var dbCollection = dataPacketModel;

	if(query.db == "gps"){
		// We need to fetch from gpsStatusModel
		dbCollection = gpsStatusModel;
	} else if(query.db == "raw"){
		// We need to fetch from gpsStatusModel
		dbCollection = rawDataModel;
	}

	if(mostRecent){
		// Only fetch most recent (raw)
		dbCollection.find().
			limit(1).sort([['timestamp', -1]])
			.exec(sendData);
	} else {
		// Fetch many (not raw)
		var visibleSets = getVisibleSets(query);
		var binSize = getBins(to-from);		//in sec

		console.log(('series' in query) ? 'timestamp ' + visibleSets.join(" ") : '');

		if(binSize && binSize>0){
			// We need averaging
			winston.verbose("Averaging bin size: " + binSize);
			averageDataModel.find()
				.where('timestamp').gt(from).lte(to)
				.where('averagingPeriod').equals(binSize)
				.limit(MAX_QUERY_RESULTS).sort([['timestamp', -1]])
				.select(('series' in query) ? 'timestamp ' + visibleSets.join(" ") : '')
				.exec(sendData);
		} else {
			// No averaging needed
			winston.debug("Direct Fetch");
			dbCollection.find()
				.where('timestamp').gt(from).lte(to)
				.limit(MAX_QUERY_RESULTS).sort([['timestamp', -1]])
				.select(('series' in query) ? 'timestamp ' + visibleSets.join(" ") : '')
				.exec(sendData);
		}
	}
}
Beispiel #27
0
 disableConsole: function () {
   infoLogger.remove(infoLogger.transports.console);
   errorLogger.remove(errorLogger.transports.console);
 }
 set: function (target, prop) {
     logger.warn(`Using page.${prop} = ...; is not supported. Use page.property('${prop}', ...) instead. See the README file for more examples of page#property.`);
     return false;
 }
Beispiel #29
0
// app logger file 
var winston = require('winston');

var logger = new (winston.Logger)({
  transports: [
    new (winston.transports.Console)({ json: false, timestamp: true }),
    new winston.transports.File({ filename: './log/' + 'debug.log', json: false })
  ],
  exceptionHandlers: [
    new (winston.transports.Console)({ json: false, timestamp: true }),
    new winston.transports.File({ filename: './log/' + '/exceptions.log', json: false })
  ],
  exitOnError: false
});
// Set log levels 
logger.setLevels({debug:0, info: 1, silly:2, warn: 3, error:4});

module.exports = logger;
Beispiel #30
0
  var winston = require('winston');
  var oll = require('../lib/winston-oohlalogTransport');

    // Tests to make sure that nothing gets logged when time is off and 
    // number of logs does not reach threshold.
  var logger = new winston.Logger({
    transports: [
    new (winston.transports.OohLaLog)({
      apiKey : "1f111a85-62c7-4f42-8dd9-8a10bb80dc6e",
      hostName: "Logger",
      level : "verbose",
      debug : true,
      timedFlush : -1, // Negative value turns it off
      threshold : 26
    }),
    ]
  });

  for (var i = 0; i < 25; i++) {
    logger.log("info", i, { category : "category", details: "details"});
  }