Hi Michael,
 
sry for this late reply but unfortunately I was very busy. Thanks a lot for your help. I will try this after I'm done with a lot of other important todos and may get back to you ;)
 
Best,
Marco
 
Gesendet: Dienstag, 17. Februar 2015 um 22:03 Uhr
Von: "Michael Ferguson" <[email protected]>
An: "Brad Chamberlain" <[email protected]>
Cc: "Marco Postigo" <[email protected]>, "Public Chapel Bugs list" <[email protected]>
Betreff: Re: [Chapel-bugs] Shadowing a procedure with variable number of arguments
Hi -
 
Regarding making Logger/ConsoleLogger/etc with a Writer... as you
and Brad were discussing here:
 
My intent was to create a ConsoleLogger that is able to take any arguments
(primitives, classes, records ...). Then simply redirect the arguments to
writeln() which then (if I did not understand anything wrong) uses the
writeThis(w:Writer) procedure of classes to print them. Later I wanted to
replace the ConsoleLogger with a FileLogger that is able to do log rotating
etc... of course hoping that using the writeThis(...) method will help saving
some work :) I didn't want to override the proc +(s: string, myObject:
object) method (and the other way around ... myObject: object, s: string) in
all my classes.
 
 
To the rest of the message (the harder part), there's a part of me that wonders whether there might be a way to subclass Writer to get the behavior you want, but I'm not expert enough in the file/channel/writer/reader hierarchy to know the answer to that offhand (and the developer who is best equipped to answer it is out of the loop for another week or two; but if you weren't in a rush, it might make sense to drag feet until he gets back to see what his thoughts are).
I believe that you could do this with the Writer infrastructure, but it might give
you a more complicated-looking implementation than your original approach.
 
Here's what it would look like (although I have not tried this myself):
 
You'd create ConsoleWriter, FileWriter, and RotatingFileWriter all
as subclasses of Writer (which is defined in modules/internal/ChapelIO.chpl ).
You will have to provide implementations of the following methods:
 binary():bool
 styleElement(int):int
 error():syserr
 setError(e:syserr)
 clearError()
 writePrimitive(x)
 writeBytes(x, len:ssize_t)
 
and you can see an example in modules/standard/IO.chpl.
 
Your Writer implementations would implement those methods by creating
a ChannelWriter attached to the appropriate file/file location and then forwarding
the calls to that ChannelWriter. Unfortunately, at the moment, I don't think
there is a pleasant user-facing way to create a ChannelWriter, but if you decide
that this approach sounds interesting, we could certainly add one. In the mean
time for prototyping, I'd recommend you:
 - create/get a channel for the file/file position you want to write to
 - use the implementation-internal _channel_internal field of that channel
   as the argument to new ChannelWriter as is done in _write_one_internal
  in IO.chpl :
    var my_channel = ....
    var my_channel_writer = new ChannelWriter(_channel_internal=my_channel._channel_internal);
 
Best,
 
-michael
 
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Chapel-bugs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-bugs

Reply via email to