Lwt: Lwt_log: how can we use it?

Created on 5 Sep 2017  路  9Comments  路  Source: ocsigen/lwt

Are there simple examples to use Lwt_log to write logs? Do we need to initialize something before using Lwt_log.info "Hello, world!"?

Is it recommended to use it to log lots of information (to stdout and in files)?

docs

Most helpful comment

@dannywillems Have a look at https://github.com/dbuenzli/logs for a logging solution. It has a better API for logging and isn't Lwt specific. Lwt_log should be deprecated IMO.

All 9 comments

@dannywillems, try the code in this post: https://discuss.ocaml.org/t/about-lwt-concurrency-library/150/6:

let () =
  Lwt_log_core.default :=
    Lwt_log.channel
      ~template:"$(date).$(milliseconds) [$(level)] $(message)"
      ~close_mode:`Keep
      ~channel:Lwt_io.stdout
      ();

  Lwt_log_core.add_rule "*" Lwt_log_core.Info;

  Lwt_main.run begin
    Lwt_log_core.info "blah"
  end

(* ocamlfind opt -linkpkg -package lwt.unix foo.ml && ./a.out *)

As per that post, you would normally use module Lwt_log, not Lwt_log_core everywhere. I was just being explicit about what actual underlying module everything was coming from.

Also, even if this answers your question, let's leave the issue open to remind about improving the docs.

@dannywillems Have a look at https://github.com/dbuenzli/logs for a logging solution. It has a better API for logging and isn't Lwt specific. Lwt_log should be deprecated IMO.

Thanks @rgrinberg and @aantron. Sorry to answer now.

No worries, most open source takes place at the rate at which people happen to by luck be available :)

I'm in favor of deprecating Lwt_log in principle, as we evidently don't have the labor resources to properly maintain it. We would suggest people use logs, in particular Logs_lwt`.

I found the docs of Logs_lwt also a bit nebulous last December, so maybe they ought to be improved as well. Not sure what their current status is, and I don't remember the specific difficulties I was having. I did end up using it successfully, though.

@rgrinberg, any thoughts on what to do about Lwt_log in terms of packaging? Perhaps we could factor it out into its own package, and then constrain that package with an upper bound when Lwt_log becomes incompatible with Lwt?

Ok, I added the example to the module description, stated the relation to Lwt_log_core (telling the reader that most of Lwt_log is documented in Lwt_log_core), and recommended checking out Logs_lwt (linking to it and the home page of logs). Given the theme is we don't have enough labor resources to work on Lwt_log, including factoring it, I think this should be good for now. Please let me know any thoughts.

any thoughts on what to do about Lwt_log in terms of packaging? Perhaps we could factor it out into its own package, and then constrain that package with an upper bound when Lwt_log becomes incompatible with Lwt?

Seems like it would be easier to just fix it rather than mess around with upper bounds?

I agree with splitting the package for the purpose of getting rid of more dotted findlib names.

Factoring out Lwt_log is beginning in #484 by @hannesm, in particular see https://github.com/ocsigen/lwt/pull/484#issuecomment-338173757 for a plan.

Was this page helpful?
0 / 5 - 0 ratings