The logFaces appenders send JSON formatted log events to logFaces receivers. This appender uses HTTP to send the events (there is another logFaces appender that uses UDP).
npm install log4js @log4js-node/logfaces-http
type
-@log4js-node/logfaces-http
url
-string
- logFaces receiver servlet URLapplication
-string
(optional, defaults to empty string) - used to identify your application's logstimeout
-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 asp_
values in the logFaces event.hostname
-string
(optional) - used to add the hostnameh
property to the logFaces event.
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
.
// 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(new Error("exception message"), "something has gone wrong");
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
. The first event will have sessionID
of 111
and second will have sessionID
of 222
. Also since enableCallStack
is set, both events will include location details such as file name, function name and line number.
The second event will have a full stack trace of the Error
object passed in.
Without enableCallStack
, the Error
stack would still get logged, but not the file name, function name, and line number as those are parsed earlier.