How to use log4js - 10 common examples

To help you get started, we’ve selected a few log4js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / log4js_v1.x.x / flow_v0.25.x- / test_log4js.js View on Github external
log4js.getLogger('test').error('test', 'test');

// $ExpectError
log4js.getLogger('test').test('test');

// $ExpectError
log4js.getLogger(1);

log4js.shutdown(() => {});

// $ExpectError
log4js.shutdown();

log4js.connectLogger(log4js.getLogger(), {});

const error = log4js.levels.ERROR;
github flow-typed / flow-typed / definitions / npm / log4js_v1.x.x / flow_v0.25.x- / test_log4js.js View on Github external
// $ExpectError
log4js.configure({
  appenders: [{}],
});

log4js.getLogger().log('test');
log4js.getLogger('test').error('test', 'test');

// $ExpectError
log4js.getLogger('test').test('test');

// $ExpectError
log4js.getLogger(1);

log4js.shutdown(() => {});

// $ExpectError
log4js.shutdown();

log4js.connectLogger(log4js.getLogger(), {});

const error = log4js.levels.ERROR;
github jimivdw / grunt-mutation-testing / utils / OptionUtils.js View on Github external
function getOptions(grunt, task) {
    var globalOpts = grunt.config(task.name).options;
    var localOpts = grunt.config([task.name, task.target]).options;
    var opts = _.merge({}, DEFAULT_OPTIONS, globalOpts, localOpts);

    // Set logging options
    log4js.setGlobalLogLevel(log4js.levels[opts.logLevel]);
    log4js.configure(LOG_OPTIONS);

    opts.code = expandFiles(opts.code, opts.basePath);
    opts.specs = expandFiles(opts.specs, opts.basePath);
    opts.mutate = expandFiles(opts.mutate, opts.basePath);

    if (opts.karma) {
        opts.karma.notIncluded = expandFiles(opts.karma.notIncluded, opts.basePath);
    }

    var requiredOptionsSetErr = areRequiredOptionsSet(opts);
    if(requiredOptionsSetErr !== null) {
        grunt.warn('Not all required options have been set properly. ' + requiredOptionsSetErr);
        return null;
    }
github litixsoft / baboon / test / logging.spec.js View on Github external
if (!fs.existsSync(tmpPath)) {
            fs.mkdirSync(tmpPath);
        }

        var sut = log(config);

        expect(sut.audit).toBeDefined();
        expect(sut.syslog).toBeDefined();
        expect(sut.express).toBeDefined();

        // check log4js
        expect(log4js.appenders.file).toBeDefined();
        expect(typeof log4js.appenders.file).toBe('function');
        expect(log4js.appenders.console).toBeDefined();
        expect(typeof log4js.appenders.console).toBe('function');
        expect(log4js.appenders['log4js-node-mongodb']).toBeDefined();
        expect(typeof log4js.appenders['log4js-node-mongodb']).toBe('function');
    });
github usemodj / angularjs-express-mysql / backend / app.js View on Github external
// replace this with the log4js connect-logger
// app.use(logger('dev'));
/**
* make a log directory, just in case it isn't there.
*/
try {
    fs.mkdirSync(path.join(__dirname, './log'));
} catch (e) {
    if (e.code != 'EEXIST') {
        console.error("Could not set up log directory, error was: ", e);
        process.exit(1);
    }
}

log4js.configure(path.join(__dirname, './config/log4js.json'));
log4js.setGlobalLogLevel((app.get('env') === 'production')? log4js.levels.ERROR: log4js.levels.DEBUG);

app.use(log4js.connectLogger(log4js.getLogger('http'), { level: 'auto' }));
app.use(cookieParser());
app.use(bodyParser.json({limit:"50mb"}));
app.use(bodyParser.urlencoded({limit:"50mb", extended: true}));
app.use(methodOverride());
app.use(multipart({
    uploadDir: settings.upload_path
}));

app.use(session({
    secret: 'your-secret-here',
    name: 'connect.sid',
    resave: false,
    saveUninitialized: true,
    secure: true,
github acmeair / acmeair-nodejs / acmeairhttp / index.js View on Github external
module.exports = function (settings) {
    var module = {};
    var http = require('http')

    var contextRoot = settings.authContextRoot || "/acmeair-auth-service/rest/api"
	var location = process.env.AUTH_SERVICE;
	
    var hostAndPort = location.split(":");

	var log4js = require('log4js');
	var logger = log4js.getLogger('acmeairhttp');
	logger.setLevel(settings.loggerLevel);
	
    module.createSession = function (userid, callback /* (error, sessionId) */){
		var path = contextRoot+"/authtoken/byuserid/" + userid;
	     	var options = {
			hostname: hostAndPort[0],
		 	port: hostAndPort[1] || 80,
		    	path: path,
		    	method: "POST",
		    	headers: {
		    	      'Content-Type': 'application/json'
		    	}
	     }
	
	     logger.debug('createSession  options:'+JSON.stringify(options));
	     var request = http.request(options, function(response){
github log4js-node / log4js-node / examples / example-connect-logger.js View on Github external
// define logger
const logger = log4js.getLogger('log4jslog');

// set at which time msg is logged print like: only on error & above
// logger.setLevel('ERROR');

// express app
app.use(express.favicon(''));
// app.use(log4js.connectLogger(logger, { level: log4js.levels.INFO }));
// app.use(log4js.connectLogger(logger, { level: 'auto', format: ':method :url :status' }));

// ### AUTO LEVEL DETECTION
// http responses 3xx, level = WARN
// http responses 4xx & 5xx, level = ERROR
// else.level = INFO
app.use(log4js.connectLogger(logger, { level: 'auto' }));

// route
app.get('/', (req, res) => {
  res.send('hello world');
});

// start app
app.listen(5000);

console.log('server runing at localhost:5000');
console.log('Simulation of normal response: goto localhost:5000');
console.log('Simulation of error response: goto localhost:5000/xxx');
github ether / etherpad-lite / src / node / utils / Settings.js View on Github external
//we know this setting, so we overwrite it
    //or it's a settings hash, specific to a plugin
    if(exports[i] !== undefined || i.indexOf('ep_')==0)
    {
      exports[i] = settings[i];
    }
    //this setting is unkown, output a warning and throw it away
    else
    {
      console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
    }
  }
  
  log4js.configure(exports.logconfig);//Configure the logging appenders
  log4js.setGlobalLogLevel(exports.loglevel);//set loglevel
  log4js.replaceConsole();

  if(!exports.sessionKey){ // If the secretKey isn't set we also create yet another unique value here
    exports.sessionKey = randomString(32);
    console.warn("You need to set a sessionKey value in settings.json, this will allow your users to reconnect to your Etherpad Instance if your instance restarts");
  }

  if(exports.dbType === "dirty"){
    console.warn("DirtyDB is used. This is fine for testing but not recommended for production.");
  }
};
github hubrixco / logjack / layouts / xml.js View on Github external
function addLayout(){
    log4js.addLayout('xml', config => function (logEvent) {
        // format in xml
        var xw = new XMLWriter;
        xw.startDocument();
        xw.startElement('log');
        xw.writeElement('startTime',logEvent.startTime.toString());
        xw.writeElement('categoryName', logEvent.categoryName);
        xw.writeElement('data', logEvent.data.toString());
        xw.writeElement('level', logEvent.level.toString());
        xw.writeElement('context', JSON.stringify(logEvent.context));
        xw.writeElement('pid', logEvent.pid.toString());
        
        //xw.text(logEvent.toString());
        xw.endDocument();
     
        //console.log(xw.toString());
        return xw.toString();
github mozilla / sauropod / srv / main.js View on Github external
if (args[0] == "mock") {
	verifyFunc = dummyVerifyBrowserID;
	conf = args[1];
    } else {
	conf = args[0];
    }
}

var https = require('https');
var uuid = require('node-uuid');
var express = require('express');

var log4js = require('log4js');
var url = require('url');
log4js.addAppender(log4js.consoleAppender());
log4js.addAppender(log4js.fileAppender('logs/sauropod.log'), 'sauropod');

var connect = require('connect');
console.log('Using the "' + conf + '" config');
var config = require('./configuration').getConfig(conf);
var logger = config.logger;
logger.info('Using the "' + conf + '" config');

console.log('Using the "' + config.storage.backend + '" storage backend');
var storage = require(config.storage.backend);

var sauropod = express.createServer(); // TODO: Transition to HTTPS server
sauropod.use(connect.logger('short'));
sauropod.use(express.bodyParser());
sauropod.use(express.cookieParser());
sauropod.use(express.session({secret: 'apatosaurus'}));