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
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Chapel-bugs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-bugs