Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
syslog-client
Advanced tools
This module is a pure JavaScript implementation of the BSD Syslog Protocol RFC 3164 and the Syslog Protocol RFC 5424.
This module is installed using node package manager (npm):
npm install syslog-client
It is loaded using the require()
function:
var syslog = require("syslog-client");
TCP or UDP clients can then be created to log messages to remote hosts.
var client = syslog.createClient("127.0.0.1");
client.log("example message");
The following sections describe constants exported and used by this module.
This object contains constants for all valid values for the transport
attribute passed to the options
argument for the createClient()
function.
The following constants are defined in this object:
Tcp
Udp
This object contains constants for all valid values for the facility
attribute passed to the options
argument for the log()
method on the
Client
class. The following constants are defined in this object:
Kernel
- 0User
- 1System
- 3Audit
- 13Alert
- 14Local0
- 16Local1
- 17Local2
- 18Local3
- 19Local4
- 20Local5
- 21Local6
- 22Local7
- 23This object contains constants for all valid values for the severity
attribute passed to the options
argument for the log()
method on the
Client
class. The following constants are defined in this object:
Emergency
- 0Alert
- 1Critical
- 2Error
- 3Warning
- 4Notice
- 5Informational
- 6Debug
- 7All messages are sent using an instance of the Client
class. This
module exports the createClient()
function which is used to create
instances of the Client
class.
The createClient()
function instantiates and returns an instance of the
Client
class:
// Default options
var options = {
syslogHostname: os.hostname(),
transport: syslog.Transport.Udp,
port: 514
};
var client = syslog.createClient("127.0.0.1", options);
The optional target
parameter defaults to 127.0.0.1
. The optional
options
parameter is an object, and can contain the following items:
port
- TCP or UDP port to send messages to, defaults to 514
syslogHostname
- Value to place into the HOSTNAME
part of the HEADER
part of each message sent, defaults to os.hostname()
tcpTimeout
- Number of milliseconds to wait for a connection attempt to
the specified Syslog target, and the number of milliseconds to wait for
TCP acknowledgements when sending messages using the TCP transport,
defaults to 10000
(i.e. 10 seconds)transport
- Specify the transport to use, can be either
syslog.Transport.Udp
or syslog.Transport.Tcp
, defaults to
syslog.Transport.Udp
facility
- set default for client.log()
; default is syslog.Facility.Local0
.severity
- set default for client.log()
; default is syslog.Severity.Informational
.rfc3164
- set to false to use RFC 5424
syslog header format; default is true for the older RFC 3164
format.appName
- set the APP-NAME field when using rfc5424
; default uses process.title
dateFormatter
- change the default date formatter when using rfc5424
; interface: function(date) { return string; }
; defaults to function(date) { return date.toISOString(); }
The close
event is emitted by the client when the clients underlying TCP or
UDP socket is closed.
No arguments are passed to the callback.
The following example prints a message to the console when a clients underlying TCP or UDP socket is closed:
client.on("close", function () {
console.log("socket closed");
});
The error
event is emitted by the client when the clients underlying TCP or
UDP socket emits an error.
The following arguments will be passed to the callback
function:
error
- An instance of the Error
class, the exposed message
attribute
will contain a detailed error message.The following example prints a message to the console when an error occurs with a clients underlying TCP or UDP socket:
client.on("error", function (error) {
console.error(error);
});
The close()
method closes the clients underlying TCP or UDP socket. This
will result in the close
event being emitted by the clients underlying TCP
or UDP socket which is passed through to the client, resulting in the client
also emitting a close
event.
The following example closes a clients underlying TCP or UDP socket:
client.close();
The log()
method sends a Syslog message to a remote host.
The message
parameter is a string containing the message to be logged.
The optional options
parameter is an object, and can contain the following
items:
facility
- Either one of the constants defined in the syslog.Facility
object or the facility number to use for the message, defaults to
syslog.Facility.Local0
(see syslog.createClient()
)severity
- Either one of the constants defined in the syslog.Severity
object or the severity number to use for the message, defaults to
syslog.Severity.Informational
(see syslog.createClient()
)rfc3164
- set to false to use RFC 5424
syslog header format; default is true for the older RFC 3164
format.timestamp
- Optional Javascript Date() object to back-date the message.msgid
- Optional RFC 5424 message-id.The callback
function is called once the message has been sent to the remote
host, or an error occurred. The following arguments will be passed to the
callback
function:
error
- Instance of the Error
class or a sub-class, or null
if no
error occurredEach message sent to the remote host will have a newline character appended to it, if one is not already appended. Care should be taken to ensure newline characters are not embedded within the message passed to this method (i.e. not appearing at the end), as this may cause some syslog relays/servers to incorrectly parse the message.
The following example sends a message to a remote host:
var options = {
facility: syslog.Facility.Daemon,
severity: syslog.Severity.Critical
};
var message "something is wrong with this daemon!";
client.log(message, options, function(error) {
if (error) {
console.error(error);
} else {
console.log("sent message successfully");
}
});
Example programs are included under the modules example
directory.
Tests can be run with:
npm test
Install dev dependencies before running test coverage:
npm install --dev
npm run coverage
Coverage should be generated into coverage/lcov-report/index.html
.
console.dir()
statement accidently left in codekey
in _expandConstantObject()
missing var
declarationclose()
options
in .log()
optional as per existing documentationcb
in .log()
optional and update documentationerror
event and .log
callback wouldn't predictably receive errorclose
event is now always fired when .close()
is called, regarless of open connectionCopyright (c) 2017 Paul Grove
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
TCP and UDP syslog client RFC 5424 & RFC 3164
We found that syslog-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.