A port of log4js to node.js
The TCP appender sends log events to a master server over TCP sockets. It can be used as a simple way to centralise logging when you have multiple servers or processes. It uses the node.js core networking modules, and so does not require any extra dependencies. Remember to call log4js.shutdown
when your application terminates, so that the sockets get closed cleanly. It’s designed to work with the tcp-server, but it doesn’t necessarily have to, just make sure whatever is listening at the other end is expecting JSON objects as strings.
type
- tcp
port
- integer
(optional, defaults to 5000
) - the port to send tohost
- string
(optional, defaults to localhost
) - the host/IP address to send toendMsg
- string
(optional, defaults to __LOG4JS__
) - the delimiter that marks the end of a log messagelayout
- object
(optional, defaults to a serialized log event) - see layoutslog4js.configure({
appenders: {
network: { type: "tcp", host: "log.server" },
},
categories: {
default: { appenders: ["network"], level: "error" },
},
});
This will send all error messages to log.server:5000
.