How to use the log4js.appenders function in log4js

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 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 by-syk / NanoIconPack / server / nodejs / nano8082.js View on Github external
var app = express();

// 解析 POST application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// 解析 POST JSON
//app.use(bodyParser.json({ limit: '1mb' }));

// 支持静态文件
app.use(express.static('public'));

// console log is loaded by default, so you won't normally need to do this
//log4js.loadAppender('console');
log4js.loadAppender('file');
//log4js.addAppender(log4js.appenders.console());
log4js.addAppender(log4js.appenders.file('logs/nano' + serverPort + '.log'), 'nano' + serverPort);
var logger = log4js.getLogger('nano' + serverPort);
logger.setLevel('INFO'); // TRACE, DEBUG, INFO, WARN, ERROR, FATAL

// 用到的SQL命令
var sqlCmds = {
  req: 'INSERT IGNORE INTO req(icon, label, label_en, pkg, launcher, sys_app, icon_pack, device_id, device_brand, device_model, device_sdk) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
  sumByIpP: 'SELECT COUNT(*) AS num FROM req WHERE icon_pack = ? AND pkg = ?',
  sumByIpPDi: 'SELECT device_id, COUNT(*) AS num FROM req WHERE icon_pack = ? AND pkg = ? GROUP BY device_id = ?',
  reqTopFilterMarked: 'SELECT label, pkg, COUNT(*) AS sum, 0 AS filter FROM req AS r WHERE icon_pack = ? AND pkg NOT IN (SELECT pkg FROM req_filter AS rf WHERE rf.icon_pack = r.icon_pack AND user = ?) GROUP BY pkg ORDER BY sum DESC, pkg ASC LIMIT ?',
  //reqTopFilterMarked2: 'SELECT label, pkg, launcher, COUNT(*) AS sum, 0 AS filter FROM req AS r WHERE icon_pack = ? AND CONCAT(pkg, \'/\', launcher) NOT IN (SELECT CONCAT(pkg, \'/\', launcher) FROM req_filter AS rf WHERE rf.icon_pack = r.icon_pack AND user = ?) GROUP BY pkg, launcher ORDER BY sum DESC, pkg ASC LIMIT ?',
  reqTopFilterMarked2: 'SELECT r.label, r.pkg, r.launcher, r.sum, r.filter FROM (SELECT label, pkg, launcher, COUNT(*) AS sum, 0 AS filter FROM req WHERE icon_pack = ? GROUP BY pkg, launcher) AS r LEFT JOIN (SELECT pkg, launcher FROM req_filter WHERE icon_pack = ? AND user = ? AND launcher <> \'\') AS rf ON r.pkg = rf.pkg AND r.launcher = rf.launcher WHERE rf.pkg IS NULL ORDER BY r.sum DESC, r.pkg ASC LIMIT ?',
  reqTopOnlyMarked: 'SELECT label, pkg, COUNT(*) AS sum, 1 AS filter FROM req AS r WHERE icon_pack = ? AND pkg IN (SELECT pkg FROM req_filter AS rf WHERE rf.icon_pack = r.icon_pack AND user = ?) GROUP BY pkg ORDER BY sum DESC, pkg ASC',
  //reqTopOnlyMarked2: 'SELECT label, pkg, launcher, COUNT(*) AS sum, 1 AS filter FROM req AS r WHERE icon_pack = ? AND CONCAT(pkg, \'/\', launcher) IN (SELECT CONCAT(pkg, \'/\', launcher) FROM req_filter AS rf WHERE rf.icon_pack = r.icon_pack AND user = ?) GROUP BY pkg, launcher ORDER BY sum DESC, pkg ASC',
  reqTopOnlyMarked2: 'SELECT r.label, r.pkg, r.launcher, COUNT(*) AS sum, 1 AS filter FROM req AS r INNER JOIN req_filter AS rf ON r.icon_pack = rf.icon_pack AND r.pkg = rf.pkg AND r.launcher = rf.launcher WHERE r.icon_pack = ? AND rf.user = ? GROUP BY r.pkg, r.launcher ORDER BY sum DESC, r.pkg ASC',
  reqTop: 'SELECT label, pkg, COUNT(*) AS sum, 1 AS filter FROM req WHERE icon_pack = ? GROUP BY pkg ORDER BY sum DESC, pkg ASC LIMIT ?',
  reqTop2: 'SELECT label, pkg, launcher, COUNT(*) AS sum, 1 AS filter FROM req WHERE icon_pack = ? GROUP BY pkg, launcher ORDER BY sum DESC, pkg ASC LIMIT ?',
github ninjablocks / client / lib / Log.js View on Github external
addFileAppender: function(path) {
    if (!log4js.appenders.file) {
      log4js.loadAppender('file');
    }

    var appender = log4js.appenders.file(path, null /* default layout*/, 2097152 /* 2mb max size */, 1 /* 1 backup */);
    var filter = new logLevelFilter('INFO', appender);
    log4js.addAppender(filter);
  },
github Icemic / search.bakery.moe / server / server.js View on Github external
const through2 = require('through2');
const mongoose = require('mongoose');
const redis = require('./utils/redis');
const cors = require('kcors');


const CONFIG = require('./config/config');

// init logger

//console log is loaded by default, so you won't normally need to do this
// log4js.loadAppender('console');
log4js.loadAppender('file');
// log4js.addAppender(log4js.appenders.console());
const date = new Date();
log4js.addAppender(log4js.appenders.file(path.resolve(__dirname, `logs/${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}.log`)));

const logger = log4js.getLogger('Core');
logger.setLevel('Debug');

// logger.trace('Entering cheese testing');
// logger.debug('Got cheese.');
// logger.info('Cheese is Gouda.');
// logger.warn('Cheese is quite smelly.');
// logger.error('Cheese is too ripe!');
// logger.fatal('Cheese was breeding ground for listeria.');

logger.info('Server starting...');

(async () => {

  const app = new Koa();
github cr0hn / vulnerable-node / app.js View on Github external
var fs = require("fs");
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var log4js = require("log4js");

var init_db = require('./model/init_db');
var login = require('./routes/login');
var products = require('./routes/products');

var app = express();

// config second logger
log4js.loadAppender('file');
//log4js.addAppender(log4js.appenders.console());
log4js.addAppender(log4js.appenders.file('app-custom.log'), 'vnode');

var logger4js = log4js.getLogger('vnode');
logger4js.setLevel('INFO');

var accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'))

/*
 * Template engine
 */
app.engine('ejs', engine);

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
app.use(logger('combined', {stream: accessLogStream}));
github ninjablocks / client / lib / Log.js View on Github external
addFileAppender: function(path) {
    if (!log4js.appenders.file) {
      log4js.loadAppender('file');
    }

    var appender = log4js.appenders.file(path, null /* default layout*/, 2097152 /* 2mb max size */, 1 /* 1 backup */);
    var filter = new logLevelFilter('INFO', appender);
    log4js.addAppender(filter);
  },
github fontello / fontello / lib / system / runner / initialize.js View on Github external
options.file.logSize * 1024 * 1024, // logSize
          options.file.backups                // numBackups
        );
      }

      let myLevel = baseLevel;

      if (appenderConfig.level) {
        myLevel = log4js.levels.toLevel(appenderConfig.level, baseLevel);

        // get upper threshold
        myLevel = myLevel.isGreaterThanOrEqualTo(baseLevel) ? myLevel : baseLevel;
      }

      // return thresholded appender
      let appender = log4js.appenders.logLevelFilter(myLevel, log4js.levels.FATAL, appenders[appenderConfig.file]);

      appendersInGroup.push(appender);

      groupLevel = groupLevel.isGreaterThanOrEqualTo(myLevel) ? myLevel : groupLevel;
    });
github fontello / fontello / lib / system / runner / initialize.js View on Github external
function clusteredAppender(children, category) {
    let clusterAppenderConfig = {
      appenders: [],      // configs
      actualAppenders: [] // functions
    };

    children.forEach(appender => {
      clusterAppenderConfig.appenders.push({ category });
      clusterAppenderConfig.actualAppenders.push(appender);
    });

    return log4js.appenders.clustered(clusterAppenderConfig);
  }
github cliffano / couchtato / lib / util.js View on Github external
function Util(stat, queue, driver) {
  this.stat = stat || {};
  this.queue = queue || [];
  this.driver = driver;

  log4js.loadAppender('file');
  log4js.addAppender(log4js.appenders.file('couchtato.log'), '');
  this.logger = log4js.getLogger('');
  this.logger.setLevel('INFO');
}
github xiaojue / fd-server / lib / server / task / index.js View on Github external
function getLogger(dir){
    log4js.loadAppender('file');
    log4js.appenders['TASK'] = [];
    var appender = log4js.appenders.file(dir + "/tast.log");
    if(log4js.hasLogger("TASK")){
        log4js.getLogger('TASK').removeAllListeners();
    }
    log4js.addAppender(appender,'TASK');
    return log4js.getLogger('TASK');
}