Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/herp-inc/bs-winston
bucklescript interface for winstonjs
https://github.com/herp-inc/bs-winston
Last synced: about 1 month ago
JSON representation
bucklescript interface for winstonjs
- Host: GitHub
- URL: https://github.com/herp-inc/bs-winston
- Owner: herp-inc
- License: mit
- Created: 2018-12-18T09:32:18.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T19:54:40.000Z (over 2 years ago)
- Last Synced: 2023-03-02T05:41:39.904Z (almost 2 years ago)
- Language: OCaml
- Homepage:
- Size: 51.8 KB
- Stars: 4
- Watchers: 24
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
bs-winston
===Bucklescript bindings for (subset of) [winston](https://github.com/winstonjs/winston)@3.x
```ocaml
module Log = Winston.SyslogMake(struct
let transports = [Winston.Transport.console ()]
let formats = [
Winston.Format.label ~label: "test" ~message: false;
Winston.Format.timestamp ();
Winston.Format.json ();
]
let level = `Debug
end)let () =
Log.log `Info "Hello World" ();
Log.log `Crit "OCaml. Not Ocaml." ();
Log.log `Err "Oops" ();;
```## contents
```ocaml
module Winston : sig
module type LogLevel
module type LOGmodule Transport
module Format
module Make
module SyslogMake
module NpmMake
end
```### `Transport` submodule for [transports](https://github.com/winstonjs/winston#transports)
```ocaml
module Transport : sig
type t
val console : ?eol:string -> unit -> t
val file : ?eol:string
-> ?dirname:string
-> ?filename:string
-> unit
-> t
end
```We support `Console` and `File`, with partial options.
### `Format` submodule for [formats](https://github.com/winstonjs/winston#formats)
```ocaml
module Format : sig
type t
val label : label:string -> message:bool -> t
val json : ?space:int -> unit -> t
val timestamp : ?format:string -> unit -> t
end
```### `LogLevel` signature
This signature represents the first argument of `Make`.```ocaml
module type LogLevel = sig
type tval string_of_t : t -> string
val enabled : t list
end
```### `Make` functor
This functor generates a logger module.`LOG` signature represents the logger module.
```ocaml
module type LOG = sig
type tval log: t -> string -> ?meta:string Js.Dict.t -> unit -> unit
end
``````ocaml
module Make(Level : LogLevel)(Conf : sig
val transports : Transport.t
val formats : Format.t list
val level : Level.t
end)
: LOG with type t = Level.t
```#### `SyslogMake` and `NpmMake` functor
These functors are ones partially applied `Make`.```ocaml
module SyslogMake(Conf : sig
val transports : Transport.t
val formats : Format.t list
val level : syslog_t
end)
: LOG with type t = syslog_t
``````ocaml
module NpmMake(Conf : sig
val transports : Transport.t
val formats : Format.t list
val level : npm_t
end)
: LOG with type t = npm_t
```
and we provide `syslog_t` and `npm_t` as polymorphic variant type
```ocaml
type syslog_t = [
| `Emerg
| `Alert
| `Crit
| `Err
| `Warn
| `Notice
| `Info
| `Debug
]type npm_t = [
| `Err
| `Warn
| `Info
| `Http
| `Verbose
| `Debug
| `Silly
]
```These are alias of `Winston_syslog.LogLevel.t` and `Winston_npm.LogLevel.t`
```ocaml
module Winston_syslog.LogLevel : LogLevel = struct
type t = [
| `Emerg [@bs.as "emerg"]
| `Alert [@bs.as "alert"]
| `Crit [@bs.as "crit"]
| `Err [@bs.as "error"]
| `Warn [@bs.as "warning"]
| `Notice [@bs.as "notice"]
| `Info [@bs.as "info"]
| `Debug [@bs.as "debug"]
] [@@bs.deriving jsConverter]let enabled = [`Emerg; `Alert; `Crit; `Err; `Warn; `Notice; `Info; `Debug]
let string_of_t x = tToJs x
end
``````ocaml
module Winston_npm.LogLevel : LogLevel = struct
type t = [
| `Err [@bs.as "error"]
| `Warn [@bs.as "warn"]
| `Info [@bs.as "info"]
| `Http [@bs.as "http"]
| `Verbose [@bs.as "verbose"]
| `Debug [@bs.as "debug"]
| `Silly [@bs.as "silly"]
] [@@bs.deriving jsConverter]......
end
```You can follow these implementatoins to write custom module denoting `LogLevel`.
## License
See `LICENSE`