npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bs-winston

v0.7.2

Published

Winston for ReasonML

Downloads

5

Readme

npm

BsWinston

This is adapter of winston for ReasonML. Because ReasonML is significantly different from js the API here is decidedly different from vanilla winston API. See the API section and examples below.

Install

npm install bs-winston

And to bsconfig.json: "bs-dependencies": [..., "bs-winston", ...]

Examples

Initialize/Setup a logger e.g. in MyLogger.re you write:

module Format = BsWinston.Format;
module Transport = BsWinston.Transport;

let logger =
  BsWinston.Builder.(
    create()
    -> setLevel(Debug)
    -> addFormat(Format.createSimple())
    -> addTransport(Transport.createConsole(()))
    -> build);

Use the logger above in another module:

module L = BsWinston.Logger;
let logger = MyLogger.logger;

L.logInfoMsg(logger, "This is info message");
L.logWarnMsg(logger, "This messege is sent at warn level");

try (Js.Exn.raiseError("log this")) {
  | error => L.logErrorExn(logger, "Never fails to fail", error)
}

/* In a complicated case you may want to send extra json keys. It is possible: */
logger
-> L.info
-> L.withMessage("the usual")
-> L.withJson("keyX", Js.Json.string("valueX"))
-> L.withJson("keyY", Js.Json.number(float_of_int(42)))
-> L.log;

API

Logger (module BsWinston.Logger)

  • Logger instance is of type BsWinston.Logger.t
  • Set level:
    • error: t => t
    • warn: t => t
    • info: t => t
    • verbose: t => t
    • debug: t => t
    • silly: t => t
    The functions do not mutate but rather create a new logger with the requested level.
  • Combinators:
    • withMessage: t => 'a => t

      Converts the message (2nd arg) into string (with Js.String.make) and combines it with the possible message in the logger (1st arg) (with one space " " in between to avoid clumping)

    • withExn: t => exn => t

      Converts the exception to Js.Json.t if it is Js.Exn.t or just stringifies other ocaml exceptions and sets the result to a field ("error" by default) which can be defined on logger options. (This function does not combine with itself i.e. latter usage overwrites the previous)

    • withJson: t => string => Js.Json.t => t

      Sets the json to a field named with the string parameter.

  • Output
    • log: t => unit

      Produces the side-effect of logging to the logger transport.

  • Convenience functions to make some common use cases less verbose:
    • logErrorMsg = (logger, msg) => logger -> error -> withMessage(msg) -> log
    • logErrorExn = (logger, msg, error) => logger -> error -> withMessage(msg) -> withExn(error) -> log
    • logWarnMsg = (logger, msg) => logger -> warn -> withMessage(msg) -> log
    • logInfoMsg = (logger, msg) => logger -> info -> withMessage(msg) -> log
    • logDebugMsg = (logger, msg) => logger -> debug -> withMessage(msg) -> log

Builder (module BsWinston.Builder)

Loggers can be build either with Builder functions or directly with Logger.create (which is sligthly more lower level).

  • create: unit => t Create a builder. ! This is without trasport and you need at least one transport to create a valid logger.
  • setLevel: t => level => t Logger wide max level to output.
  • setSilent: t => bool => t
  • addFormat: t => Format.t => t (See Formats) (The list will be auto-combined for winston)
  • addTransport: t => Transport.t => t (See Transports)
  • errorKey: t => string => t Set field for error content
  • build: t => Logger.t Create the logger instance.

Format (module BsWinston.Format)

Create winston formats with functions:

  • createAlign
  • createCli
  • createColorize
  • createJson
  • createLabel
  • createLogstash
  • createMetadata
  • createMs
  • createPadLevels
  • createPrettyPrint
  • createPrintf
  • createSimple
  • createSplat
  • createTimestamp
  • createUncolorize

See the src/Format.rei file for function argument details and the logform for further explanations.

Simple custom filters (without Symbol manipulation) can be created with:

  • fromMapFn: (Js.Dict.t(Js.Json.t) => Js.Dict.t(Js.Json.t)) => t

    The function given as argument takes the info object and returns manipulated info object which is then forwarded in the formatting chain.

Transport (module BsWinston.Transport)

Create winston transports with functions:

  • createConsole
  • createFile
  • createHttp
  • createStream

See the src/Transport.rei file for function argument details and the winston for further explanations.

Other transports: