@tsed/logger-logstash-udp
v6.7.8
Published
Logstash UDP appender module for @tsed/logger
Downloads
44
Maintainers
Readme
@tsed/logger-logstash-udp
A package of Ts.ED logger framework.
Features
The logstash appenders for Ts.ED Logger.
The logstash-udp appender supports sending log events to a Logstash server.
It uses the node.js core UDP support, and so requires no extra dependencies.
Remember to call logger.shutdown
in your application if you want the UDP socket closed cleanly.
Installation
npm install --save @tsed/logger-logstash-udp
Configuration
type
-logstash-udp
options.host
-string
- hostname (or IP-address) of the logstash serveroptions.port
-integer
- port of the logstash serveroptions.layout
- (optional, defaults to dummyLayout) - used for the message field of the logstash data (see layouts)options.extraDataProvider
- function (optional, defaults to put the second param of log to fields) - used to enhance the object sent to Logstash via UDP. this will be passed the log event and should return an object.
Example
import {Logger} from "@tsed/logger";
import "@tsed/logger-logstash-udp";
const logger = new Logger("loggerName");
logger.appenders.set("stdout", {
type: "logstash-udp",
level: ["info"],
options: {
host: "log.server",
port: 12345
}
});
logger.info("important log message", {cheese: "gouda", biscuits: "hobnob"});
This will result in a JSON message being sent to log.server:12345 over UDP, with the following format:
{
'@version': '1',
'@timestamp': '2014-04-22T23:03:14.111Z',
'host': 'yourHostname',
'level': 'INFO',
'category': 'default',
'message': 'important log message',
'fields': {
'biscuits': 'hobnob',
'cheese': 'gouda'
}
}
use extraDataProvider
import {Logger} from "@tsed/logger";
import "@tsed/logger-logstash-udp";
const logger = new Logger("loggerName");
logger.appenders.set("stdout", {
type: "loggly",
level: ["info"],
options: {
host: "log.server",
port: 12345,
extraDataProvider: (loggingEvent) => ({
host: "anotherHostname", // this will replace the default real host
clientIp: "1.2.3.4", // this will be added
fields: {
tag: "myTag", // this will be added to the fields
pid: loggingEvent.pid, // this will be added to the fields
cheese: "defaultCheese" // this will be added to the fields but will not be replaced in this example
}
})
}
});
logger.info("important log message", {cheese: "gouda", biscuits: "hobnob"});
This will result in a JSON message being sent to log.server:12345 over UDP, with the following format:
{
'@version': '1',
'@timestamp': '2014-04-22T23:03:14.111Z',
'host': 'anotherHostname',
'level': 'INFO',
'category': 'default',
'message': 'important log message',
'clientIp': '1.2.3.4',
'fields': {
'cheese': 'defaultCheese',
'tag': 'myTag',
'pid': 123
}
}
So, if not using the default extraDataProvider
, you have to put the second param of the log to the fields yourself if you want.
Backers
Thank you to all our backers! 🙏 [Become a backer]
Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
License
The MIT License (MIT)
Copyright (c) 2016 - 2018 Romain Lenzotti
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.