How to use the log4js.levels 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 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 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 lisong / code-push-server / app.js View on Github external
var auth = require('./routes/auth');
var accessKeys = require('./routes/accessKeys');
var account = require('./routes/account');
var users = require('./routes/users');
var apps = require('./routes/apps');
var AppError = require('./core/app-error');
var log4js = require('log4js');
var log = log4js.getLogger("cps:app");
var app = express();
app.use(helmet());
app.disable('x-powered-by');
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

app.use(log4js.connectLogger(log4js.getLogger("http"), {level: log4js.levels.INFO, nolog:'\\.gif|\\.jpg|\\.js|\\.css$' }));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

//use nginx in production
//if (app.get('env') === 'development') {
  log.debug("set Access-Control Header");
  app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, X-CodePush-Plugin-Version, X-CodePush-Plugin-Name, X-CodePush-SDK-Version");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,PATCH,DELETE,OPTIONS");
    log.debug("use set Access-Control Header");
    next();
  });
github fontello / fontello / lib / system / runner / initialize.js View on Github external
function initLogger(N) {
  let mainRoot     = N.mainApp.root,
      config       = _.assign({}, N.config.logger),
      options      = _.assign({ file: { logSize: 10, backups: 5 } }, config.options),
      // common logging level (minimal threshold)
      baseLevel    = log4js.levels.toLevel(options.level, log4js.levels.ALL),
      // should it log everything to console or not
      logToConsole = (N.environment !== 'production'),
      // cache of initialized appenders
      appenders    = {},
      // real loggers created for each entry in the config
      loggers      = [],
      // cache of met channels, maps full channel names to corresponding loggers
      channels     = {};


  // Layout for file loggers
  //
  //  %d - date
  //  %p - log level
  //  %z - pid
  //  %c - category
github nodeca / nodeca.core / lib / system / runner / initialize.js View on Github external
function initLogger(N) {
  let mainRoot     = N.mainApp.root,
      config       = _.assign({}, N.config.logger),
      options      = _.assign({ file: { logSize: 10, backups: 5 } }, config.options),
      // common logging level (minimal threshold)
      baseLevel    = log4js.levels.getLevel(options.level, log4js.levels.ALL),
      // should it log everything to console or not
      logToConsole = (N.environment !== 'production' || process.stdout && process.stdout.isTTY),
      // real loggers created for each entry in the config
      loggers      = [],
      // cache of met channels, maps full channel names to corresponding loggers
      channels     = {};


  // Layout for file loggers
  //
  //  %d - date
  //  %p - log level
  //  %z - pid
  //  %c - category
  //  %m - message
  //
github livegrep / livegrep / web / web_server.js View on Github external
var opts = parser.parse();
if (!opts) {
  process.exit(1);
}

log4js.configure(path.join(__dirname, "log4js.json"));

if (opts.options.autolaunch) {
  console.log("Autolaunching a back-end server...");
  require('./cs_server.js')
}

var app = express.createServer();
var logger = log4js.getLogger('web');
app.use(log4js.connectLogger(logger, {
                               level: log4js.levels.INFO,
                               format: ':remote-addr [:date] :method :url'
                             }));

app.use(express.static(path.join(__dirname, 'static')));
app.get('/', function (req, res) {
          res.redirect('/index.html');
        })

app.listen(8910);
console.log("http://localhost:8910");

var server = dnode(new Server().Server);
server.listen(app, {
                io: {
                  transports: ["htmlfile", "xhr-polling", "jsonp-polling"]
                }
github polotek / log4js-syslog / index.js View on Github external
var log4js = require('log4js')
	, syslog = require('node-syslog');


var levels = {}
levels[log4js.levels.ALL] = syslog.LOG_DEBUG;
levels[log4js.levels.TRACE] = syslog.LOG_DEBUG;
levels[log4js.levels.DEBUG] = syslog.LOG_DEBUG;
levels[log4js.levels.INFO] = syslog.LOG_INFO;
levels[log4js.levels.WARN] = syslog.LOG_WARNING;
levels[log4js.levels.ERROR] = syslog.LOG_ERR;
levels[log4js.levels.FATAL] = syslog.LOG_CRIT;

function getOptions(flags) {
	var opts = 0;
	if(Array.isArray(flags)) {
		for(var i = 0, len = flags.length; i < len; i++) {
			opts = opts | flags[i];
		}
	}
	return opts;
}

function getSyslogLevel(level) {
	return level && levels[level] ? levels[level] : null;
}
github superafroman / node-torrent / lib / client.js View on Github external
var Client = function(options) {

  options = options || {};

  log4js.setGlobalLogLevel(log4js.levels[options.logLevel || 'WARN']);

  var id = options.id || '-NT0010-';
  if (id instanceof Buffer) {
    if (id.length !== 20) {
      throw new Error('Client ID must be 20 bytes');
    }
    this.id = id;
  } else {
    this.id = padId(id);
  }

  this.torrents = {};
  this.downloadPath = options.downloadPath || '.';
  this._server = net.createServer(this._handleConnection.bind(this));
  this.port = listen(this._server, options.portRange);
github dominhhai / koa-log4js / koa-logger.js View on Github external
'use strict'

const levels = require('log4js').levels
const DEFAULT_FORMAT = ':remote-addr - -' +
  ' ":method :url HTTP/:http-version"' +
  ' :status :content-length ":referrer"' +
  ' ":user-agent"'
/**
 * Log requests with the given `options` or a `format` string.
 * Use for Koa v1
 *
 * Options:
 *
 *   - `format`        Format string, see below for tokens
 *   - `level`         A log4js levels instance. Supports also 'auto'
 *
 * Tokens:
 *
 *   - `:req[header]` ex: `:req[Accept]`