mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
1.2 KiB
1.2 KiB
TCP Appender
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.
Configuration
type-tcpport-integer(optional, defaults to5000) - the port to send tohost-string(optional, defaults tolocalhost) - 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 layouts
Example
log4js.configure({
appenders: {
network: { type: "tcp", host: "log.server" },
},
categories: {
default: { appenders: ["network"], level: "error" },
},
});
This will send all error messages to log.server:5000.