any logger in core?

Francois francois.berenger.fun at gmail.com
Thu Nov 8 03:48:14 GMT 2012



On Wednesday, November 7, 2012 6:57:04 PM UTC+9, David House wrote:
>
> You need to start the scheduler. You should do this in all async 
> programs, or else nothing will get run. Creating a log creates an 
> async Pipe.t, and doing Log.foo puts things onto that Pipe.t. There is 
> an async job to read things off of the pipe and to write them out. But 
> if you don't start the scheduler, this job won't get run. So add the 
> following at bottom of your code: 
>
> let () = 
>   main (); 
>   never_returns (Scheduler.go ()) 
>

I don't know where to find never_returns.

But the following did work (and never stop):
---
module Log   = Async_extra.Log
module Sched = Async.Std.Scheduler

let main () =

  let logger = Log.create (Log.Level.of_string "Debug") [Log.Output.screen] 
in

  Log.raw   logger "%s\n" "raw log";
  Log.info  logger "%s\n" "info log";
  Log.error logger "%s\n" "error log";
  Log.debug logger "%s\n" "debug log";

  Log.close logger
;;

main();
Sched.go ()
---
 

>
> The reason this is done, rather than just writing immediately, is in 
> case the write blocks,


I see.

 

> which would halt the whole process. If you 
> decide you don't care about this risk (e.g. if you're writing to a 
> terminal then it's not very likely), you can use Log.Blocking. 
>

I'll try to use that. 


> Also, a smaller point, it's more idiomatic to write "open Async.Std" 
> rather than referring directly to one of the three async 
> sub-libraries. 
>

I'm affraid of open directives, I try to keep my code _very_ explicit
about what it is doing and which function from which module is used
(maybe because of past overexposure to some C++ code).

For the moment, I use the stdlib + batteries
+ (async and async_extra for just the logger).

In some other future thread, I might ask for some help on the
best way to remove batteries, then remove the stdlib,
hopefully to just depend on core and async in the future.

Thanks for all the help,
Francois.
 

>
> On Wed, Nov 7, 2012 at 8:34 AM, Francois Berenger 
> <francois.ber... at gmail.com <javascript:>> wrote: 
> > I could create a test program. 
> > 
> > It compiles, at least, but has the funny property of not logging 
> anything out. 
> > 
> > --- 
> > module Log  = Async_extra.Log 
> > 
> > let main () = 
> > 
> >   let logger = Log.create (Log.Level.of_string "Debug") 
> [Log.Output.screen] in 
> > 
> >   Log.raw   logger "%s\n" "raw log"; 
> >   Log.info  logger "%s\n" "info log"; 
> >   Log.error logger "%s\n" "error log"; 
> >   Log.debug logger "%s\n" "debug log"; 
> > 
> >   Log.close logger 
> > ;; 
> > 
> > main() 
> > --- 
> > 
> > Here is the oasis file for it: 
> > --- 
> > OASISFormat: 0.3 
> > Name:        Toto 
> > Version:     0.1 
> > Synopsis:    Titi 
> > Authors:     Me 
> > License:     LGPL-3 
> > Plugins:     META (0.3), DevFiles (0.3) 
> > 
> > Executable logger_test 
> >   Path:           . 
> >   BuildDepends:   async_extra 
> >   BuildTools:     ocamlbuild 
> >   CompiledObject: native 
> >   MainIs:         logger_test.ml 
> > --- 
> > 
> > I was thinking all logs would print right away. 
> > 
> > Regards, 
> > F. 
> > 
> > On Wed, Nov 7, 2012 at 4:18 PM, Francois Berenger 
> > <francois.ber... at gmail.com <javascript:>> wrote: 
> >> Hello, 
> >> 
> >> How can I construct a value of type Async_extra.Log.Level 
> >> and an Async_extra.Log.Output? 
> >> 
> >> Sorry for the stupid question but I have never used 
> >> polymorphic variants. 
> >> 
> >> If you can point me to some simple explanation 
> >> on them, I will go and read it too 
> >> (I looked at http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html 
> >> but it does not tell me why I should use them, just how). 
> >> 
> >> Thanks a lot, 
> >> F. 
> >> 
> >> 
> >> On Wednesday, November 7, 2012 10:59:54 AM UTC+9, Francois Berenger 
> wrote: 
> >>> 
> >>> Yes I saw it, thanks. 
> >>> 
> >>> I'll also take a look at the .mli file, as I was advised to do so by 
> >>> David House. 
> >>> I'll try to make an example program to check I can use it correctly. 
> >>> 
> >>> On Tue, Nov 6, 2012 at 12:12 PM, Yaron Minsky <ymi... at janestreet.com<javascript:>> 
>
> >>> wrote: 
> >>> > No, did you see my link?  You can read the ocamldocs: 
> >>> > 
> >>> > 
> >>> > 
> https://ocaml.janestreet.com/ocaml-core/108.07.01/doc/async_extra/Log.html 
> >>> > 
> >>> > On Mon, Nov 5, 2012 at 9:51 PM, Francois Berenger 
> >>> > <francois.ber... at gmail.com <javascript:>> wrote: 
> >>> >> Argh! I'm forced to read an mli file. ;) 
> >>> >> 
> >>> >> On Mon, Nov 5, 2012 at 8:15 PM, David House <dho... at janestreet.com<javascript:>> 
>
> >>> >> wrote: 
> >>> >>> Judging from the mli, there should be some ocamldocs, yes. 
> >>> >>> 
> >>> >>> However, I recommend just looking at the mli. 
> >>> >>> 
> >>> >>> On Mon, Nov 5, 2012 at 6:08 AM, Francois Berenger 
> >>> >>> <francois.ber... at gmail.com <javascript:>> wrote: 
> >>> >>>> 
> >>> >>>> Is there some ocamldoc for it? 
> >>> >>>> 
> >>> >>>> I think I managed to compile the ocamldoc for core and async, but 
> did 
> >>> >>>> not find anything about a Log module into it. 
> >>> >>>> 
> >>> >>>> 
> >>> >>>> On Sunday, November 4, 2012 9:15:45 PM UTC+9, Yaron Minsky wrote: 
> >>> >>>>> 
> >>> >>>>> Don't feel too bad about knowing about it.  It's quite new. 
> >>> >>>>> 
> >>> >>>>> But yeah, moving to it eventually sounds right. 
> >>> >>>>> 
> >>> >>>>> On Sat, Nov 3, 2012 at 6:43 PM, Sean McLaughlin <
> sea... at gmail.com> 
> >>> >>>>> wrote: 
> >>> >>>>>> 
> >>> >>>>>> No, sorry.  I didn't know about Async.Log, and I wrote my own 
> >>> >>>>>> logger. 
> >>> >>>>>> Switching to this one is probably a good idea in the long run 
> for 
> >>> >>>>>> omake-server. 
> >>> >>>>>> 
> >>> >>>>>> On Thu, Nov 1, 2012 at 10:14 PM, Yaron Minsky 
> >>> >>>>>> <ymi... at janestreet.com> 
> >>> >>>>>> wrote: 
> >>> >>>>>> > Sean, does your omake-server use Async.Log?  That might be a 
> good 
> >>> >>>>>> > example. 
> >>> >>>>>> > 
> >>> >>>>>> > y 
> >>> >>>>>> > 
> >>> >>>>>> > On Thu, Nov 1, 2012 at 9:59 PM, Francois Berenger 
> >>> >>>>>> > <francois.ber... at gmail.com> wrote: 
> >>> >>>>>> >> Is there some example program using this logger? 
> >>> >>>>>> >> 
> >>> >>>>>> >> 
> >>> >>>>>> >> On Friday, November 2, 2012 10:40:40 AM UTC+9, Francois 
> Berenger 
> >>> >>>>>> >> wrote: 
> >>> >>>>>> >>> 
> >>> >>>>>> >>> OK, I'm hooked now. 
> >>> >>>>>> >>> 
> >>> >>>>>> >>> I plus core in my new project. 
> >>> >>>>>> >>> 
> >>> >>>>>> >>> Thanks! 
> >>> >>>>>> >>> F. 
> >>> >>>>>> >>> 
> >>> >>>>>> >> 
> >>> >>>>> 
> >>> >>>>> 
> >>> >>>> 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/core/attachments/20121107/1ca31e29/attachment-0001.html>


More information about the core mailing list