slf4ts-log4js
log4js Logging-Binding for slf4ts
It's meant to be used with nodejs
.
Example Usage
Example package.json:
{
...,
"dependencies": {
"slf4ts-log4js": "latest"
},
...
}
Example code:
import { configure } from "log4js";
import { LoggerFactory, LoggerConfiguration } from "slf4ts-api";
const ROOT_LOGGER = LoggerFactory.getLogger();
ROOT_LOGGER.setMetadata({ application: 'my-app' });
// configure log4js as usual
configure({
appenders: {
out: { type: 'stdout' },
app: { type: 'file', filename: 'application.log' }
},
categories: {
default: { appenders: [ 'out', 'app' ], level: 'debug' }
}
});
/**
* prints something like:
*
* [2020-01-01T11:22:33.444] [INFO] default - Test Message { version: '1.0.0' } Error:
* at Object.<anonymous> (...)
* at Module._compile (internal/modules/cjs/loader.js:1151:30)
* at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
* at Module.load (internal/modules/cjs/loader.js:1000:32)
* at Function.Module._load (internal/modules/cjs/loader.js:899:14)
* at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
* at internal/main/run_main_module.js:17:47
*
* { application: 'my-app' } (metadata set above) is present in the context of the logger.
*/
ROOT_LOGGER.info("Test Message", { version: '1.0.0' }, new Error());