Git Product home page Git Product logo

log4js-json-layout's People

Contributors

aalexgabi avatar bencehornak avatar engeenity avatar fluxsauce avatar id0sch avatar ironyman avatar veetil09 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

log4js-json-layout's Issues

include not working?

I must be missing something. I can only include startTime, categoryName, level, and data in my json output.

It appears to be because the formatter code selects the fields from output instead of data:

    // Only include fields specified in 'include' field
    // if field is specified
    if (config.include && config.include.length) {
      const newOutput = {};
      _.forEach(config.include, (key) => {
        if (_.has(output, key)) {
          newOutput[key] = output[key];
        }
      });
      return newOutput;
    }

data is set earlier as a clone of the formatter input:

  function formatter(raw) {
    const data = _.clone(raw);
...

and output specifically only selects a few fields:

    const output = {
      startTime: data.startTime,
      categoryName: data.categoryName,
      level: data.level.levelStr,
    };

It would appear that this bit of code at line 105:

        if (_.has(output, key)) {
          newOutput[key] = output[key];
        }

should be:

        if (_.has(data, key)) {
          newOutput[key] = data[key];
        }

Am I missing something? I assume I'm doing something wrong...

inspect() not working for error objects?

I also noticed error objects are spitting out incorrect messages.

This is evident just by running mocha:

  1) log4js-json-layout should format stack traces:
     AssertionError: expected '{"startTime":"615 Ludlam Place, Nicholson, New Mexico, 5763","categoryName":"572efdaaa64be9dbc56369ae","level":"INFO","data":"{ inspect: [Function: inspect] }"}' to include '"data":"Error: Whoops!\\n    at Context.<anonymous>'
      at Context.<anonymous> (test/unit/lib/jsonLayout.js:68:19)
      at processImmediate (internal/timers.js:461:21)

The data field is supposed to be the stack trace, but instead it's coming out"data":"{ inspect: [Function: inspect] }".

It would appear something has changed between node and maybe lodash to cause this.

I don't quite get how this is supposed to work. I'd be happy to put together a PR to fix this, but I need to determine root cause first.

Can someone explain how inspect() is supposed to work?

function wrapErrorsWithInspect(items) {
  return _(items).map((item) => {
    if (_.isError(item) && item.stack) {
      return {
        inspect() {
          return `${util.format(item)}\n${item.stack}`;
        },
      };
    } else if (!_.isObject(item)) {
      return item;
    }
    return undefined;
  }).compact().value();
}

function formatLogData(data) {
  return util.format(...wrapErrorsWithInspect(data));
}

Is there a way to rename the data attribute to some other name

I would like to change the layout from:

{"startTime":"2019-02-28T04:27:24.363Z","categoryName":"app","level":"INFO","data":"Test log 1000000000"}

to

{"startTime":"2019-02-28T04:27:24.363Z","categoryName":"app","level":"INFO","message":"Test log 1000000000"}

Can you guide me how to do it ?

How to use log4js-json-layout with confiuguration file

Hello,
To vet something more conformtable I use log4js with a configuration file like:


{
    "appenders": {
        "services" : {
            "type": "dateFile",
            "filename": "../logs/cld-apps-services.log",
            "pattern": "-yyyy-MM-dd",
            "maxLogSize": 20480,
            "backups": 3
        },
        "billing": {
            "type": "dateFile",
            "filename": "../logs/cld-apps-billing.log",
            "pattern": "-yyyy-MM-dd",
            "maxLogSize": 20480,
            "backups": 10
        },
        "accessLog": {
            "type": "dateFile",
            "filename": "../logs/cld-apps-access-log.log",
            "pattern": "-yyyy-MM-dd",
            "maxLogSize": 20480,
            "backups": 3
        },
		"errorFile": {
			"type": "file",
			"filename": "../logs/cld-apps-errors.log", 
			"layout": { 
				"type": "messagePassThrough" 
            }
		},
        "errors": { 
            "type": "logLevelFilter",
            "level": "ERROR",
            "appender": "errorFile"
        },
        "testu": {
            "type": "dateFile",
            "filename": "../logs/testu.log",
            "pattern": "-yyyy-MM-dd",
            "maxLogSize": 20480,
            "backups": 3
        },
        "console": {
            "type": "console"
        },
        "stdout": {
            type: "stdout"
        },
        "cloudstdout": {
            "type": "logLevelFilter",
            "level": "DEBUG",
            "appender": "stdout"
        },
        "stderr": {
            type: "stderr"
        },
        "cloudstdout": {
            "type": "logLevelFilter",
            "level": "ERROR",
            "appender": "stderr"
        }
	},
	"categories": {
		"default": { "appenders": ["console", "cloudstdout", "cloudstderr"], "level": "INFO" },
		"testu": { "appenders": ["testu", "services"], "level": "TRACE" },
		"testi": { "appenders": ["testu", "services"], "level": "TRACE" },
		"jmcnet": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"jmcnet.emailTemplate": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "DEBUG" },
		"ppnjs": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"access-log": { "appenders": ["services", "accessLog", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"cld-apps": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"cld-apps.billing": { "appenders": ["services", "errors", "billing", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"cld-apps.models": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"cld-apps.models.baseSchema": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "WARN" },
		"cld-apps.models.accounts": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"cld-apps.models.mailpoeteAccount": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"cld-apps.models.spaces": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "DEBUG" },
		"cld-apps.models.files": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "DEBUG" },
		"cld-apps.models.fileSpaces": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "DEBUG" },
		"cld-apps.utils": { "appenders": ["services", "errors" ], "level": "INFO", "cloudstdout", "cloudstderr" },
		"cld-apps.utils.helperAws": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "DEBUG" },
		"cld-apps.utils.helperZip": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "DEBUG" },
		"cld-apps.services": { "appenders": ["services", "errors" ], "level": "INFO", "cloudstdout", "cloudstderr" },
		"cld-apps.services.periodics": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"cld-apps.services.accounts": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "INFO" },
		"cld-apps.services.spaces": { "appenders": ["services", "errors", "cloudstdout", "cloudstderr" ], "level": "DEBUG" }
	}
}

My question is how to use a JSON layout with this kind of configuration file ? I cannot find any documentation on that

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.