Bucklescript bindings for (subset of) winston@3.x
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" ();;
module Winston : sig
module type LogLevel
module type LOG
module Transport
module Format
module Make
module SyslogMake
module NpmMake
end
Transport
submodule for transports
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
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
This signature represents the first argument of Make
.
module type LogLevel = sig
type t
val string_of_t : t -> string
val enabled : t list
end
This functor generates a logger module.
LOG
signature represents the logger module.
module type LOG = sig
type t
val log: t -> string -> ?meta:string Js.Dict.t -> unit -> unit
end
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
These functors are ones partially applied Make
.
module SyslogMake(Conf : sig
val transports : Transport.t
val formats : Format.t list
val level : syslog_t
end)
: LOG with type t = syslog_t
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
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
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
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
.
See LICENSE