1.0.0 • Published 5 years ago

@churchill/http v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

HTTP transport

Send your logged data to a http endpoint.

npm install @churchill/http

Usage

const churchill = require("@churchill/core");
const HTTP = require("@churchill/http");

const httpTransport = HTTP.create({
  method: "POST",
  url: "https://localhost:5000/log",
  // @ts-ignore
  cert: fs.readFileSync(certFile),
  key: fs.readFileSync(keyFile),
  ca: fs.readFileSync(caFile),
  format: info => ({ ...info, http: true })
})
httpTransport.on("error", (err) => {
  // handle potential errors
})

const createNamespace = churchill({
  transports: [
    httpTransport
  ]
});

const logger = createNamespace("worker:1");
logger.info("...");

Options

OptionDescriptionExample
methodHTTP method{ method: "POST" }
urlURL{ url: "https://log.example.com" }
authAuthentication, see auth request options{ auth: { username: "john", password: "xxxxx" } }
headersHTTP headers{ headers: { "Content-Type": "application/json" } }
dataKeyHow to send the data (e.g. body, qs, json, form, formData). This will use the request appropriate body key, which sets required headers. Defaults to json.{ dataKey: "form" }
formatCustom formatting function.{ format: (info, out, logger) => ... }
maxLevelMax level to log into this transport.{ maxLevel: "warn" }