How to use the log4js.layouts 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 fontello / fontello / lib / system / runner / initialize.js View on Github external
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
  //  %m - message
  //
  let plainLayout    = log4js.layouts.layout('pattern',
                         { pattern: '[%d] [%p] %z %c - %m' }
                       );

  // Layout for console loggers
  //
  // only difference is `%[`..`%]` - defines highlighted (coloured) part
  //
  let colouredLayout = log4js.layouts.layout('pattern',
                         { pattern: '%[[%d] [%p] %z %c -%] %m' }
                       );

  //
  // define system (general) logger
  //

  N.logger = log4js.getLogger('system');
github fontello / fontello / lib / system / runner / initialize.js View on Github external
//
  //  %d - date
  //  %p - log level
  //  %z - pid
  //  %c - category
  //  %m - message
  //
  let plainLayout    = log4js.layouts.layout('pattern',
                         { pattern: '[%d] [%p] %z %c - %m' }
                       );

  // Layout for console loggers
  //
  // only difference is `%[`..`%]` - defines highlighted (coloured) part
  //
  let colouredLayout = log4js.layouts.layout('pattern',
                         { pattern: '%[[%d] [%p] %z %c -%] %m' }
                       );

  //
  // define system (general) logger
  //

  N.logger = log4js.getLogger('system');

  //
  // provide a wrapper to set global log level
  //

  N.logger.setLevel = function (level) {
    level = log4js.levels[level.toUpperCase()];
    log4js.setGlobalLogLevel(level);
github NetEase / pomelo-logger / lib / logger.js View on Github external
module.exports = {
	getLogger: getLogger,
	getDefaultLogger: log4js.getDefaultLogger,

	addAppender: log4js.addAppender,
	loadAppender: log4js.loadAppender,
	clearAppenders: log4js.clearAppenders,
	configure: configure,

	replaceConsole: log4js.replaceConsole,
	restoreConsole: log4js.restoreConsole,

	levels: log4js.levels,
	setGlobalLogLevel: log4js.setGlobalLogLevel,

	layouts: log4js.layouts,
	appenders: log4js.appenders
};
github litixsoft / log4js-node-mongodb / lib / index.js View on Github external
function mongodbAppender(config) {
    if (!config || !config.connectionString) {
        throw new Error('connectionString is missing. Cannot connect to mongdb.');
    }

    var collection;
    var cache = [];
    var layout = config.layout || log4js.layouts.messagePassThroughLayout;
    var collectionName = config.collectionName || 'log';
    var connectionOptions = config.connectionOptions || {};

    function ERROR(err) {
        Error.call(this);
        Error.captureStackTrace(this, this.constructor);

        this.name = err.toString();
        this.message = err.message || 'error';
    }

    function replaceKeys(src) {
        var result = {};

        function mixin(dest, source, cloneFunc) {
            if (lxHelpers.isObject(source)) {
github hmalphettes / log4js-elasticsearch / lib / log4js-elasticsearch-layouts.js View on Github external
/**
  some idea; maybe not so good:
  support the pattern layout but make it as a json serialization ?
*/
var layouts = require('log4js').layouts;
module.exports = layouts;

var messagePassThroughLayout = layouts.messagePassThroughLayout;

/*
log4js logging event:
startTime: date,
categoryName: string,
level: { level: int, levelStr: levelStr },
data: [ args of logger ],
logger: ... circular ...
*/


/**
 * Outputs a JSON object
github polotek / log4js-syslog / index.js View on Github external
return function(loggingEvent) {
		var level = getSyslogLevel(loggingEvent.level)
			, data = loggingEvent.data
			, layout

	  if(level) {
	  	layout = config && config.layout ? config.layout : log4js.layouts.basicLayout; 
			data = layout(loggingEvent);

		  syslog.log(level, data);
		}
  };
}