### Install npm using curl Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md Instructions to install Node Package Manager (npm) using a curl command, typically for Unix-like systems. This is a prerequisite for installing Node.js packages. ```bash $ curl http://npmjs.org/install.sh | sh ``` -------------------------------- ### Install winston and winston-syslog via npm Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md Commands to install the core winston logging library and its dedicated syslog transport using npm. These packages are essential for integrating syslog logging capabilities into a Node.js application. ```bash $ npm install winston $ npm install winston-syslog ``` -------------------------------- ### Basic Usage of winston-syslog Transport in JavaScript Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md Demonstrates how to require the winston-syslog transport and add it to an existing winston logger instance in a Node.js application. This setup configures winston to send log messages to a syslog server, using default or specified options. ```js const winston = require('winston'); // // Requiring `winston-syslog` will expose // `winston.transports.Syslog` // require('winston-syslog').Syslog; winston.add(new winston.transports.Syslog(options)); ``` -------------------------------- ### Define Syslog-ng Filter by Program Name Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md This `syslog-ng` filter definition allows for filtering log messages based on the program name. In this example, it creates a filter named `fnord_f` that matches messages originating from the program 'fnord'. This filter can then be applied in log statements to direct specific application logs. ```syslog-ng filter fnord_f { program("fnord"); }; ``` -------------------------------- ### winston-syslog Transport Configuration Options Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md Detailed documentation for the configuration options available when initializing the winston-syslog transport. These options allow fine-grained control over connection parameters, network protocol, process identification, and TLS settings for secure logging to a syslog server. ```APIDOC winston.transports.Syslog Options: host: The host running syslogd, defaults to localhost. port: The port on the host that syslog is running on, defaults to syslogd's default port. protocol: The network protocol to log over (e.g. `tcp4`, `udp4`, `tls4`, `unix`, `unix-connect`, etc), defaults to `udp4`. protocolOptions: Socket connect options. See `net.socket.connect` for available options. path: The path to the syslog dgram socket (i.e. `/dev/log` or `/var/run/syslog` for OS X). pid: PID of the process that log messages are coming from (Default `process.pid`). facility: Syslog facility to use (Default: `local0`). localhost: Host to indicate that log messages are coming from (Default: `localhost`). type: The type of the syslog protocol to use (Default: `BSD`, also valid: `'3164'`, `'5424'`, `'RFC3164'` or `'RFC5424'`). app_name: The name of the application (Default: `process.title`). eol: The end of line character to be added to the end of the message (Default: Message without modifications). secureProtocol: See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions for more information on this option, passed through from this constructor. ciphers: See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions for more information on this option, passed through from this constructor. ecdhCurve: See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions for more information on this option, passed through from this constructor. rejectUnauthorized: See https://nodejs.org/api/tls.html#new-tlstlssocketsocket-options for more information on this option, passed through from this constructor. requestCert: See https://nodejs.org/api/tls.html#new-tlstlssocketsocket-options for more information on this option, passed through from this constructor. ``` -------------------------------- ### Configure Syslog-ng for TCP Input and File Output Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md This configuration block for `syslog-ng` sets up a TCP source to listen on all interfaces (0.0.0.0) on port 514, allowing up to 256 concurrent connections. It also defines a destination to log messages from the 'fnord' application to `/var/log/fnord.log`, and then links them in a log statement. ```syslog-ng source tcp_s { tcp(ip(0.0.0.0) port(514) max-connections(256)); }; destination fnord_d { file("/var/log/fnord.log"); }; log { source(tcp_s); destination(fnord_d); }; ``` -------------------------------- ### Configure Winston Logger with Syslog Levels Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md This snippet demonstrates how to initialize a Winston logger instance to use syslog-compatible log levels. It configures the logger to use the `winston.config.syslog.levels` and adds a `Syslog` transport, ensuring only syslog-supported levels are processed and levels not matching syslog will be ignored. ```js const winston = require('winston'); const logger = winston.createLogger({ levels: winston.config.syslog.levels, transports: [ new winston.transports.Syslog() ] }); ``` -------------------------------- ### Syslog-ng Log Statement for Another Application Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md This `syslog-ng` log statement demonstrates how to route logs for a different application, 'bnord', using the same TCP source. It applies a specific filter (`bnord_f`) and directs the output to a dedicated destination (`bnord_d`), requiring prior definition of these components for the new application. ```syslog-ng log { source(tcp_s); filter(bnord_f); destination(bnord_d); }; ``` -------------------------------- ### Set Node.js Process Title for Syslog Filtering Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md This JavaScript snippet shows how to set the `process.title` variable in a Node.js application. Setting this title is crucial for `syslog-ng` to correctly filter logs based on the program name, allowing specific applications to be routed to their designated log files as configured on the syslog server. ```js process.title = 'fnord'; ``` -------------------------------- ### Update Syslog-ng Log Statement with Program Filter Source: https://github.com/winstonjs/winston-syslog/blob/master/README.md This snippet modifies an existing `syslog-ng` log statement to incorporate a program-specific filter. It directs logs from the `tcp_s` source, filtered by `fnord_f`, to the `fnord_d` destination, ensuring only messages from the 'fnord' program are processed and logged to the specified file. ```syslog-ng log { source(tcp_s); filter(fnord_f); destination(fnord_d); }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.