adobe / helix-log

Log framework designed for use with project helix
Apache License 2.0
3 stars 9 forks source link

Add easy way to inject process.env variables to json formatter #27

Closed tripodsan closed 5 years ago

tripodsan commented 5 years ago

it would be cool if there is a simple way to inject process.env variables to the formatter, so that certain environment variables are logged automatically.

tripodsan commented 5 years ago

suggestion: create a envInjectionMessageDelegator that adds the env variables to the json data:

const logger = new CoralogixLogger(apyKey, appName, subsystemName, {
  level: 'debug',
  formatter: envInjectionMessageDelegator({
    ow: {
      activationId: '__OW_ACTIVATION_ID',
      actionName: '__OW_ACTION_NAME',
    },
  }, messageFormatJson),
});

rootLogger.loggers.set('coralogix', logger);

this will produce log data like:

{
   "level": "info",
   "ow": {
     "activationId": "c3933fb666f1bc8222f90640fdf9dbf1ecbc0d90f6e06b80914fe8718cd69285",
     "actionName": "helix-test/main@1.2.3" 
  },
   "message": "creating 42 tasks for testing",
   "timestamp": "2019-09-19T01:45:57.615Z" 
}