GrayGelf
GrayLog2 GELF UDP logging, streaming, chunking, and more. Production tested. Includes client and server implementations. AFAIK a complete GELF implementation. Node Core style server and client.
Install
npm install graygelf
Client (i.e. as a UDP-based logging tool)
Usage
var graygelf = require('graygelf')
var logger = graygelf.createClient({ host: 'graylog.server.local', facility: 'sample_facility'})
logger.on('error', console.error)
logger.info('Howdy GrayLog')
logger.error('oh no', new Error('bad news'))
logger.log('emerg', 'noes')
Available Options
host: (graylog host)
port: (graylog port)
facility: (graylog facility - optional for GELF 1.1)
chunkSize: (size of chunked messages in bytes, defaults to 1240)
compressType: (type of compression: 'gzip' or 'deflate', defaults to 'deflate')
mock: (mock a UDP client (no UDP client is actually used -- for testing or development enviroments), defaults to false)
Syslog Levels
GrayGelf maps the syslog levels to functions as follows:
logger.emerg('short message', 'detailed message')
logger.alert(...)
logger.crit(...)
logger.error(...)
logger.warn(...)
logger.notice(...)
logger.info(...)
logger.debug(...)
logger.log(level, short, full)
Each logger function takes two parameters which can be of any type but typically (string, object)
.
Chunked Messages
GrayGelf automatically sends chunked messages when a message gets above a certain size:
logger.chunkSize = 10
logger.emerg('some thing more than 10 bytes', 'more detail')
Streaming Messages
Each log level has an associated writeable stream .stream
that can be used to pipe data into
fs.createReadStream('./data').pipe(logger.stream.info)
Server (make your own GrayLog UDP server or intercept messages to GrayLog)
Usage (callback style)
var server = graygelf.createServer(function (msg) {
console.log('recieved message', msg)
})
server.on('error', console.error)
server.listen(12201)
Usage (evented style)
var server = graygelf.createServer().listen()
server.on('message', function (msg) {
console.log('received message', msg)
})
server.on('error', console.error)
Message Support
GrayGelf handles zlib
, gzip
and chunked messages when a message gets above a certain size.
Efficient GrayLog Proxy and Interceptor
var server = graygelf.createServer().listen(12202)
var client = graygelf.createClient({ host: 'other.server.local', port: 12201 })
server.pipe(client)
server.on('message', function (msg) {
console.log('received message', msg)
})
client.on('error', console.error)
server.on('error', console.error)
License
(The MIT License)
Copyright (c) 2014 Marc Harter wavded@gmail.com
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.