slf4ts-log4js
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

slf4ts-log4js

log4js Logging-Binding for slf4ts

NPM Version License Dependencies Status

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());

License

MIT

Package Sidebar

Install

npm i slf4ts-log4js

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

28.5 kB

Total Files

19

Last publish

Collaborators

  • rstiller