New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

logagent-js

Package Overview
Dependencies
Maintainers
1
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logagent-js - npm Package Compare versions

Comparing version 1.0.31 to 1.1.0

103

bin/logagent.js

@@ -23,3 +23,2 @@ #!/usr/bin/env node

var Logsene = require('logsene-js')
var logger = null
var Tail = require('tail-forever')

@@ -31,3 +30,5 @@ var fs = require('fs')

var http = require('http')
var loggers = {}
process.on('beforeExit', function () {})
function getFilesizeInBytes (filename) {

@@ -59,8 +60,64 @@ var stats = fs.statSync(filename)

function textMsgBodyHandler (req,res) {
function getLogger (token, type) {
var key = token + type
// console.log(token)
if (!loggers[key]) {
var logger = new Logsene(token, type)
logger.on('log', function (data) {
console.log(data)
})
logger.on('error', console.error)
loggers[key] = logger
}
return loggers[key]
}
function logToLogsene (token, type, data) {
var logger = getLogger(token, type)
logger.log(data.level || data.severity || 'info', data.message, data)
}
function getLoggerForToken (token, type) {
return function (err, data) {
if (!err && data) {
log(err, msg)
// delete data.ts
// data['_type'] = type
var msg = data
if (type === 'heroku') {
msg = {
'@timestamp': new Date(),
message: data.message,
app: data.app,
host: data.host,
severity: data.severity,
facility: data.facility
}
}
logToLogsene(token, type, msg)
}
}
}
function herokuHandler (req, res) {
var token = req.url.split('/')[1]
var body = ''
req.on('data', function (data) {
body += data
body += data
})
req.on('end', function () {
var lines = body.split('\n')
lines.forEach(function () {
parseLine(body, argv.n || 'heroku', getLoggerForToken(token, 'heroku'))
})
res.end('ok\n')
})
}
function cloudFoundryHandler (req, res) {
var body = ''
req.on('data', function (data) {
body += data
})
req.on('end', function () {
parseLine(body, argv.n || 'cloudfoundry', log)

@@ -70,5 +127,11 @@ res.end('ok\n')

}
function getHttpServer (port) {
server = http.createServer(textMsgBodyHandler)
return server.listen(port)
function getHttpServer (port, handler) {
var _port = port || process.env.PORT
if (port === true) // a commadn line flag was set but no port given
{
_port = process.env.PORT
}
var server = http.createServer(handler)
console.log('Logagent listening (http): ' + _port)
return server.listen(_port)
}

@@ -105,2 +168,5 @@

function log (err, data) {
if (err) {
return
}
if (!data) {

@@ -111,3 +177,3 @@ emptyLines++

if (argv.t) {
logger.log(data.level || data.severity + '' || 'info', data.message, data)
logToLogsene(argv.t || logseneToken, data['_type'] || argv.n || 'logs', data)
}

@@ -138,2 +204,3 @@ if (argv.s) {

rl.on('close', terminate)
rl.on('finish', terminate)
}

@@ -152,9 +219,19 @@

}
process.exit()
setTimeout(function () {
console.log(Object.keys(loggers))
Object.keys(loggers).forEach(function (l, i) {
console.log('send ' + l)
loggers[l].send()
})
}, 300)
setTimeout(function () {
console.log('Good Bye!!!')
process.exit()
}, 1000)
}
if (logseneToken) {
logger = new Logsene(logseneToken, 'logs')
if (argv.cfhttp) {
getHttpServer(argv.cfhttp, cloudFoundryHandler)
}
if(argv.cfhttp) {
getHttpServer(argv.cfhttp)
if (argv.heroku) {
getHttpServer(argv.heroku, herokuHandler)
}

@@ -171,3 +248,3 @@ if (argv._.length > 0) {

try {
var syslogServer = getSyslogServer(logseneToken, argv.u)
getSyslogServer(logseneToken, argv.u)
} catch (err) {

@@ -174,0 +251,0 @@ console.error(err)

6

lib/index.js

@@ -66,3 +66,3 @@ /*

if (src && src.patterns) {
return this.sources [sourceName].patterns
return this.sources[sourceName].patterns
}

@@ -131,3 +131,3 @@ var exclude = []

for (var i = 0; i < p.fields.length; i++) {
var value = match [i + 1]
var value = match[i + 1]
if (!isNaN(value)) {

@@ -198,3 +198,3 @@ value = Number(value)

}
if(!parsed.message && parsed.msg) {
if (!parsed.message && parsed.msg) {
parsed.message = parsed.msg

@@ -201,0 +201,0 @@ }

@@ -30,3 +30,3 @@ 'use strict'

this.lines.push(line)
} else {// reading in block
} else { // reading in block
if (this.opt.delimiter.test(line)) {

@@ -43,2 +43,1 @@ this.consumer(this.lines.join('\n'))

module.exports = MultiLine
{
"name": "logagent-js",
"version": "1.0.31",
"version": "1.1.0",
"description": "Smart log parser written in Node",

@@ -10,3 +10,4 @@ "main": "lib/index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node bin\/logagent.js --heroku $PORT"
},

@@ -13,0 +14,0 @@ "repository": {

@@ -114,3 +114,3 @@ # logagent-js

# Install logagent-js globally
# Install logagent-js as command line tool
```

@@ -133,2 +133,4 @@ npm i -g logagent-js

multi-line patterns working on stdin because the status is tracked by the source name.
- --heroku PORT listens for heroku logs (http drain / framed syslog over http)
- --cfhttp PORT listens for CLoudFoundry logs (syslog over http)
- list of files, watched by tail-forver starting at end of file to watch

@@ -135,0 +137,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc