Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
winston-gelf-transporter
Advanced tools
Readme
A Winston transporter for sending GELF messages to your Graylog server.
To install with npm
npm install winston-gelf-transporter
ES6 style
import WinstonGelfTransporter from 'winston-gelf-transporter';
CommonJS
const WinstonGelfTransporter = require('winston-gelf-transporter');
You can create a new transporter as such
const transporter = new WinstonGelfTransporter();
You can also pass a TransporterOptions
object to the constructor
const transporter = new WinstonGelfTransporter({
level: string, // optional - logging level for the transporter
silent: boolean, // optional - true to turn off output
handleExceptions: boolean,
version: string, // Graylog communication version, default 1.1
host: string, // Host for your graylog server, default 127.0.0.1
port: number, // Port for your graylog server, default 12201
protocol: string, // The input protocol for your GELF input, default 'udp'
hostName: string, // The name of the host for your Node.js app
additional: Object // Additional defaults to add to your messages
})
All you need to do is add the transporter to your winston logger.
import winston from 'winston';
import WinstonGelfTransporter from 'winston-gelf-transporter';
logger = winston.createLogger({
level: winston,
transports: [
winston.transports.Console,
// Add the Graylog transporter to the logger
new WinstonGelfTransporter({
host: 'graylog.example.com',
port: 12345,
hostName: 'client.example.com',
additional: {
foo: 'Bar'
}
})
]
});
// 1. Log a string
logger.info('Something');
// 2. Log an object
logger.info({ hello: 'world' });
// 3. Log a string message with object
logger.info('Something', { hello: 'world' });
// 4. Log an error
logger.error(new Error());
// 5. Log an error with a message
logger.error(new Error('Something'));
// 6. Or log a message with an error
logger.error('Something', new Error());
The above logging statements will result in the following
1.
{
"version":"1.1",
"short_message":"Something",
"timestamp":1577041912.451,
"host":"client.example.com",
"level":6,
"foo": "Bar"
}
2.
{
"version":"1.1",
"short_message":"{\"hello\":\"world\"}",
"timestamp":1577041912.452,
"host":"client.example.com",
"level":6,
"foo": "Bar"
}
3.
{
"version":"1.1",
"short_message":"{\"message\":\"Something\",\"hello\":\"world\"}",
"timestamp":1577041912.452,
"host":"client.example.com",
"level":6,
"foo": "Bar"
}
4.
{
"version":"1.1",
"short_message":"Error",
"timestamp":1577041912.453,
"host":"client.example.com",
"full_message":"Error\n <extended stack trace>",
"level":3,
"foo": "Bar"
}
5.
{
"version":"1.1",
"short_message":"Something",
"timestamp":1577041912.453,
"host":"client.example.com",
"full_message":"Error: Something\n <extended stack trace>",
"level":3,
"foo": "Bar"
}
6.
{
"version":"1.1",
"short_message":"Something",
"timestamp":1577041912.453,
"host":"client.example.com",
"full_message":"Error\n <extended stack trace>",
"level":3,
"foo": "Bar"
}
FAQs
A Winston transporter for sending GELF messages
The npm package winston-gelf-transporter receives a total of 1,901 weekly downloads. As such, winston-gelf-transporter popularity was classified as popular.
We found that winston-gelf-transporter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.