# A little advice on writing a logWriter

**URL:** <https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923>\
**Category:** Ruby\
**Created:** [March 15, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923 "2007-03-15T16:58:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexander\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@alexander\_j](https://www.ruby-forum.com/u/alexander_j)\
**Post date:** [March 15, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923/1 "2007-03-15T16:58:48Z")

</div>

Hello everyone,

I’m new to Ruby and not so experienced programmer in overall but i  
manage to do “ok”. Now I started to program a bit in Ruby and wanted  
to write a logWriter program but the problem is that Ruby doesnt have  
I/O Stream functions like java and C++.

I have never written a simple log writer before either, this will be  
challenging. Is there any advice on how to proceed you could give a  
fellow rookie ruby lover? 🙂

Cheers,

RubyNub

---

<div class="post-metadata">

**Author:** ![alexander\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@alexander\_j](https://www.ruby-forum.com/u/alexander_j)\
**Post date:** [March 15, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923/2 "2007-03-15T17:09:52Z")

</div>

On 3/15/07, Alexander J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello everyone,
> 
> I’m new to Ruby and not so experienced programmer in overall but i  
> manage to do “ok”. Now I started to program a bit in Ruby and wanted  
> to write a logWriter program but the problem is that Ruby doesnt have  
> I/O Stream functions like java and C++.

Instead it has a quite capable File class.

> I have never written a simple log writer before either, this will be  
> challenging. Is there any advice on how to proceed you could give a  
> fellow rookie ruby lover? 🙂

Take a look at log4r ([http://log4r.sourceforge.net](http://log4r.sourceforge.net)). It aims to  
resemble log4j/log4cpp as much as possible.

---

<div class="post-metadata">

**Author:** ![alexander\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@alexander\_j](https://www.ruby-forum.com/u/alexander_j)\
**Post date:** [March 15, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923/3 "2007-03-15T17:31:55Z")

</div>

Alexander J. schrieb:

> Hello everyone,
> 
> I’m new to Ruby and not so experienced programmer in overall but i  
> manage to do “ok”. Now I started to program a bit in Ruby and wanted  
> to write a logWriter program but the problem is that Ruby doesnt have  
> I/O Stream functions like java and C++.

log\_fd = File.new(“test\_log”, “w+”)  
or just open an existing one

log\_fd.write(str)  
or  
log\_fd \<\< “str”  
log\_fd.flush

you can also use sprintf

log\_fd.write(sprintf “%d”, var)

log\_fd.close

have a look to  
[http://www.ruby-doc.org/core/classes/IO.html](http://www.ruby-doc.org/core/classes/IO.html)

is this you are looking for?

regards

karl

---

<div class="post-metadata">

**Author:** ![alexander\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@alexander\_j](https://www.ruby-forum.com/u/alexander_j)\
**Post date:** [March 15, 2007, 6:41pm UTC](https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923/4 "2007-03-15T18:41:04Z")

</div>

Ooh. From personal experience log4r is rather poorly documented (in  
bad moods I’d call it abysmal, but right now, I’ll just say poor). If  
you have trouble, just post it here and folks who’ve used it will  
help.

I’m trying to find the script I had that used it extensively to show  
another example, but it may have gotten purged…

–Kyle

---

<div class="post-metadata">

**Author:** ![alexander\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@alexander\_j](https://www.ruby-forum.com/u/alexander_j)\
**Post date:** [March 15, 2007, 6:22pm UTC](https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923/5 "2007-03-15T18:22:01Z")

</div>

Thanks Vlad, I will take a look at it right now.

---

<div class="post-metadata">

**Author:** ![alexander\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@alexander\_j](https://www.ruby-forum.com/u/alexander_j)\
**Post date:** [March 15, 2007, 8:24pm UTC](https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923/6 "2007-03-15T20:24:21Z")

</div>

On Mar 15, 2007, at 12:39 PM, Kyle S. wrote:

> Ooh. From personal experience log4r is rather poorly documented (in  
> bad moods I’d call it abysmal, but right now, I’ll just say poor). If  
> you have trouble, just post it here and folks who’ve used it will  
> help.

You could read the standard logger library which is pretty easy to  
follow.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![alexander\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@alexander\_j](https://www.ruby-forum.com/u/alexander_j)\
**Post date:** [September 25, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/a-little-advice-on-writing-a-logwriter/88923/7 "2007-09-25T23:05:44Z")

</div>

Alex Hedin schrieb:

> Hello!
> 
> What I want do do is to make a logwriter so I can store the  
> information that comes in from a given network. For example I would  
> like to see what kind of data I’m receiving from that network by  
> having this logwriter storing that info for me.  
> there is doc for the socket class, this is much easier to write the  
> whole stuff then in C  
> [http://www.ruby-doc.org/stdlib/libdoc/socket/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/socket/rdoc/index.html)

maybe this is interessting for you  
[http://www.ruby-doc.org/stdlib/libdoc/drb/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/drb/rdoc/index.html)  
[http://www.chadfowler.com/ruby/drb.html](http://www.chadfowler.com/ruby/drb.html)

> I went and looked at this link: ([http://log4r.sourceforge.net](http://log4r.sourceforge.net))
> 
> But that is a completely done written logging program right? What I  
> would want do to, is to write one of my own. I thought they were  
> simpler than that… CAn you give mne advice on how to proceed?

> components should be (apart from write and read methods) in my  
> logwriter…

I don’t know either, I am sorry. I never write a logwriter before, I  
just logged some messages with the classes above (socket and DRb).

regards

karl
