Skip to content

Lwt_log: how can we use it? #468

Closed
Closed

Description

@dannywillems

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)?

Activity

  1. aantron commented on Sep 6, 2017

    @aantron
    Collaborator

    @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.

  2. aantron commented on Sep 6, 2017

    @aantron
    Collaborator

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

  3. rgrinberg commented on Sep 6, 2017

    @rgrinberg
    Contributor

    @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.

  4. dannywillems commented on Sep 27, 2017

    @dannywillems
    MemberAuthor

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

  5. aantron commented on Oct 12, 2017

    @aantron
    Collaborator

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

  6. aantron commented on Oct 13, 2017

    @aantron
    Collaborator

    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?

  7. aantron commented on Oct 13, 2017

    @aantron
    Collaborator

    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.

  8. rgrinberg commented on Oct 14, 2017

    @rgrinberg
    Contributor

    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.

  9. aantron commented on Oct 20, 2017

    @aantron
    Collaborator

    Factoring out Lwt_log is beginning in #484 by @hannesm, in particular see #484 (comment) for a plan.

  10. added a commit that references this issue on Oct 16, 2025
    af91fad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions