-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sarvesh Chitko
committed
Feb 26, 2019
1 parent
602d703
commit d4979f7
Showing
19 changed files
with
197 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports=class{constructor(o){this.options=o}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this.exports=class{constructor(s){this.options=s}}; |
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @module LogstashTransport | ||
* @author Sarvesh Chitko ([email protected]) | ||
*/ | ||
const winston = require("winston") | ||
const UDPInput = require("./UDPInput.class") | ||
const TCPInput = require("./TCPInput.class") | ||
const WebSocketInput = require("./WebSocketInput.class") | ||
const HTTPInput = require("./HTTPInput.class") | ||
/** | ||
* @class LogstashTransport | ||
* @extends Transport | ||
* @desc The main class that adds the Logstash capabilities to Winston | ||
*/ | ||
module.exports = | ||
class LogstashTransport extends winston.Transport { | ||
/** | ||
* | ||
* @param {Object} options - The Configuration object | ||
* @param {String} options.name - The name of the transport | ||
* @param {String} options.input - The input that you want to use | ||
* @param {String} options.host - The Logstash server host | ||
* @param {String} options.port - The port of the Logstash pipeline you've configured | ||
*/ | ||
constructor(options){ | ||
super(options) | ||
this.name='LogstashTransport' | ||
this.input=options.input | ||
this.host = options.host | ||
this.port = options.port | ||
if(this.input && this.host && this.port){ | ||
if(this.input=="udp"){ | ||
this.input = new UDPInput(options) | ||
} | ||
else if(this.input=="tcp"){ | ||
this.input = new TCPInput(options) | ||
} | ||
else if(this.input=="websocket"){ | ||
this.input = new WebSocketInput(options) | ||
} | ||
else if(this.input=="http"){ | ||
this.input = new HTTPInput(options) | ||
} | ||
else { | ||
throw new Error("Unspupported Input \""+this.input+"\". It should be either udp, tcp, websocket or http"); | ||
} | ||
} | ||
else{ | ||
throw new Error("Error creating the Logstash Object, one or more parameter missing.") | ||
} | ||
} | ||
/** | ||
* @function log | ||
* @param {Object} info - The log object that needs to be sent to Logstash | ||
* @param {Function} callback - Callback function to call, once processing the log message is processed | ||
*/ | ||
log(info,callback) { | ||
setImmediate(()=>{ | ||
this.input.send(info) | ||
this.emit('logged',info) | ||
}) | ||
callback() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { gulp,parallel,src,dest } = require("gulp") | ||
const concat = require("gulp-concat") | ||
const minify = require("gulp-minify") | ||
function combineClasses(cb){ | ||
src("src/*.class.js").pipe(minify()).pipe(dest("./dist/")) | ||
cb() | ||
} | ||
function uglifyMain(cb){ | ||
src("src/index.js").pipe(minify()).pipe(dest("./dist/")) | ||
cb() | ||
} | ||
exports.default = parallel(combineClasses,uglifyMain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @module LogstashTransport~HTTPInput | ||
*/ | ||
module.exports= | ||
/** | ||
* @class HTTPInput | ||
* @desc The class that does transmission of logs using the HTTP Requests | ||
*/ | ||
class HTTPInput { | ||
/** | ||
* @param {Object} options - The options object returned from the LogstashTransport class | ||
*/ | ||
constructor(options){ | ||
this.options=options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @module LogstashTransport~TCPInput | ||
*/ | ||
const net = require("net") | ||
module.exports= | ||
/** | ||
* @class TCPInput | ||
* @desc The class that does transmission of logs using the TCP input | ||
* @example node examples/basic-tcp.js | ||
*/ | ||
class TCPInput { | ||
/** | ||
* | ||
* @param {Object} options - The options object returned from the LogstashTransport class | ||
*/ | ||
constructor(options){ | ||
this.options=options | ||
this.connect() | ||
} | ||
connect() { | ||
this.client = net.createConnection({port:this.options.port,host:this.options.host},()=>{ | ||
this.client.unref() | ||
}) | ||
} | ||
send(message,callback) { | ||
this.client.write(JSON.stringify(message)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @module LogstashTransport~UDPInput | ||
*/ | ||
const dgram = require("dgram") | ||
const os = require("os") | ||
|
||
module.exports= | ||
/** | ||
* @class UDPInput | ||
* @desc The class that does transmission of logs using the UDP input | ||
* @example node examples/basic-udp.js | ||
*/ | ||
class UDPInput { | ||
/** | ||
* | ||
* @param {Object} options - The options object returned from the LogstashTransport class | ||
*/ | ||
constructor(options){ | ||
this.options=options | ||
this.connect() | ||
|
||
} | ||
/** | ||
* @desc The function that creates the UDP socket | ||
*/ | ||
connect() { | ||
this.client = dgram.createSocket("udp4") | ||
this.client.unref() | ||
} | ||
/** | ||
* | ||
* @param {String} message - The log object that needs to be sent to Logstash | ||
* @param {Object} callback - The callback function to be called after the write is finished | ||
* @desc The function that sends the actual message to UDP | ||
*/ | ||
send(message,callback) { | ||
let buffer = Buffer.from(message.toString()); | ||
this.client.send(buffer,0,buffer.length,this.options.port,this.options.host,callback) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @module LogstashTransport~WebSocketInput | ||
*/ | ||
this.exports= | ||
/** | ||
* @class WebSocketInput | ||
* @desc The class that does transmission of logs using the WebSockets | ||
*/ | ||
class WebSocketInput { | ||
/** | ||
* | ||
* @param {Object} options - The options object returned from the LogstashTransport class | ||
*/ | ||
constructor(options){ | ||
this.options=options | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
* @author Sarvesh Chitko ([email protected]) | ||
*/ | ||
const winston = require("winston") | ||
const UDPInput = require("./UDPInput") | ||
const TCPInput = require("./TCPInput") | ||
const WebSocketInput = require("./WebSocketInput") | ||
const HTTPInput = require("./HTTPInput") | ||
const UDPInput = require("./UDPInput.class-min") | ||
const TCPInput = require("./TCPInput.class-min") | ||
const WebSocketInput = require("./WebSocketInput.class-min") | ||
const HTTPInput = require("./HTTPInput.class-min") | ||
/** | ||
* @class LogstashTransport | ||
* @extends Transport | ||
|