log4js-node / logFaces-HTTP

LogFaces HTTP appender for log4js-node
Apache License 2.0
6 stars 3 forks source link

Add `eventLayout` config option #31

Closed ZachHaber closed 2 years ago

ZachHaber commented 2 years ago

closes #1

eventLayout lets you have fine-grained control over what you are sending to the logfaces server.

For example, if you want relative file path names being sent in f instead of absolute:

log4js.configure({
  appenders: {
    logfaces: {
      type: "@log4js-node/logfaces-http",
      url: "http://lfs-server/logs",
      eventLayout: (event, lfEvent)=>{
        if(lfEvent.f){
          lfEvent.f = path.relative(path.resolve(), lfEvent.f);
        }
        return lfEvent;
      }
    },
  },
  categories: {
    default: { appenders: ["logfaces"], level: "info", enableCallStack: true },
  },
});

Or if you want to add commas between separate data entries:

{
  eventLayout: (event, lfEvent)=>({
    ...lfEvent,
    m: event.data.map(item=>util.format(item)).join(', ');
  })
}
lamweili commented 2 years ago

I made some changes to the commits:

lamweili commented 2 years ago

@ZachHaber This PR should be good to go once the review comments are addressed. 🤗

lamweili commented 2 years ago

@ZachHaber Just a little more miscellaneous changes.

I tried to include most in suggestions so that you can Commit suggestion or Add suggestion to batch to make your life easier. There is one for n which I'm not exactly sure the type which may require a manual commit.