graylog
Tiny typed library to send compressed, chunked log messages to Graylog via GELF.
Installing
npm install @therockstorm/graylog --save
Usage
import { Graylog } from "@therockstorm/graylog"
import { name } from "../package.json"
// Configure log to include defaults in each message
const log = new Graylog({
host: "localhost", // default
port: 12201, // default
defaults: {
host: name, // defaults to os.hostname()
myCustomField: { hello: { there: "world" } }
}
})
// Log logger errors to console
log.on("error", err => console.error("@therockstorm/graylog error", err))
const app = async (): Promise<void> => {
log.info("Hello, info.")
// Include new defaults in each message
log.addDefaults({ requestId: "myId" })
log.warning("Hello, warning.", { facility: "MyApp" })
log.error("Hello, error.", new Error("boom"))
// Wait for messages to send and close Graylog connection
await log.close()
}
app()
License
MIT © Rocky Warren