Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/log4js-node/logfaces-http
LogFaces HTTP appender for log4js-node
https://github.com/log4js-node/logfaces-http
Last synced: 3 months ago
JSON representation
LogFaces HTTP appender for log4js-node
- Host: GitHub
- URL: https://github.com/log4js-node/logfaces-http
- Owner: log4js-node
- License: apache-2.0
- Created: 2018-07-02T21:58:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-10T01:03:49.000Z (about 1 year ago)
- Last Synced: 2024-09-17T07:59:49.012Z (4 months ago)
- Language: JavaScript
- Size: 570 KB
- Stars: 6
- Watchers: 4
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logFaces Appender (HTTP) for log4js-node
The logFaces appenders send JSON formatted log events to [logFaces](http://www.moonlit-software.com) receivers. This appender uses HTTP to send the events (there is another logFaces appender that uses [UDP](https://github.com/log4js-node/logFaces-UDP)).
```bash
npm install log4js @log4js-node/logfaces-http
```## Configuration
- `type` - `@log4js-node/logfaces-http`
- `url` - `string` - logFaces receiver servlet URL
- `application` - `string` (optional, defaults to empty string) - used to identify your application's logs
- `timeout` - `integer` (optional, defaults to 5000ms) - the timeout for the HTTP request.
- `configContext` - function (optional) returning a global context object accessible to all appenders. Properties from configContext added as `p_` values in the logFaces event.
- `hostname` - `string` (optional) - used to add the hostname `h` property to the logFaces event.
- `agent` - `http.Agent | https.Agent` (optional) - used to configure the requests being sent out if needed.
- `eventLayout` - `(LoggingEvent, LogFacesEvent) => LogFacesEvent` (optional) - allows more control and ability to modify and set the properties of the LogFacesEvent that will get sent to the server. Note: returning `null` or `undefined` will cause the event to be ignored and not logged. If `LogFacesEvent.m` is nullish, the default format for the message will be applied.This appender will also pick up Logger context values from the events, and add them as `p_` values in the logFaces event. See the example below for more details. Note that Logger context may override the same properties defined in `configContext`.
# Example (default config)
```javascript
// global context variables can be specified like this
// these variables will propagate to logFaces server with all requests
const MDC = {
sessionID: 111,
};// log4js framework configuration
log4js.configure({
appenders: {
logfaces: {
type: "@log4js-node/logfaces-http",
url: "http://lfs-server/logs",
application: "TesterApp",
configContext: () => MDC,
},
},
categories: {
default: { appenders: ["logfaces"], level: "info", enableCallStack: true },
},
});// instances of the logger is obtained from framework like this
const logger = log4js.getLogger();// local context variables can propagate to logFaces along with global context
logger.addContext("requestId", "123");
logger.info("some interesting log message");// global context variables can be modified anywhere in the app
MDC.sessionID = 222;
logger.error("something has gone wrong", new Error("exception message"));
```This example will result in two log events being sent to `lfs-server`. Both events will have a `requestId` property with a value of `123`. First event will have `sessionID` of `111` and second `sessionID` of `222`. Also since `enableCallStack` is set, both events will include location details such as file name, function name and line number. Second event will have a stack trace of a trown error.