Skip to content

Commit

Permalink
Added dist folder and gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarvesh Chitko committed Feb 26, 2019
1 parent 602d703 commit d4979f7
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 10 deletions.
1 change: 1 addition & 0 deletions dist/HTTPInput.class-min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports=class{constructor(o){this.options=o}};
1 change: 0 additions & 1 deletion src/HTTPInput.js → dist/HTTPInput.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports=
*/
class HTTPInput {
/**
*
* @param {Object} options - The options object returned from the LogstashTransport class
*/
constructor(options){
Expand Down
1 change: 1 addition & 0 deletions dist/TCPInput.class-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
1 change: 1 addition & 0 deletions dist/UDPInput.class-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
1 change: 1 addition & 0 deletions dist/WebSocketInput.class-min.js
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.
1 change: 1 addition & 0 deletions dist/index-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions dist/index.js
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()
}
}
2 changes: 1 addition & 1 deletion examples/basic-tcp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const winston = require("winston")
const LogstashTransport = require("../src/index")
const LogstashTransport = require("../dist/index-min")
const logger = winston.createLogger({
level:"info",
transports:[
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-udp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const winston = require("winston")
const LogstashTransport = require("../src/index")
const LogstashTransport = require("../dist/index-min")
const logger = winston.createLogger({
level:"info",
transports:[
Expand Down
12 changes: 12 additions & 0 deletions gulpfile.js
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)
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@chitkosarvesh/winston-logstash",
"version": "0.0.2",
"version": "0.0.3",
"description": "Adds Logstash support to Winston 3",
"main": "src/index.js",
"main": "dist/index-min.js",
"scripts": {
"test": "mocha tests/index.test.js"
},
Expand Down Expand Up @@ -33,5 +33,11 @@
"example": "examples",
"test": "tests"
},
"devDependencies": {}
"devDependencies": {
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0",
"gulp-concat": "^2.6.1",
"gulp-minify": "^3.1.0",
"gulp-uglify": "^3.0.1"
}
}
16 changes: 16 additions & 0 deletions src/HTTPInput.class.js
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;
}
}
28 changes: 28 additions & 0 deletions src/TCPInput.class.js
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))
}
}
40 changes: 40 additions & 0 deletions src/UDPInput.class.js
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)
}
}
17 changes: 17 additions & 0 deletions src/WebSocketInput.class.js
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
}
}
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4979f7

Please sign in to comment.