log4r style

J

John

I have been looking at log4r for a project that involves a
multithreaded web application.

The log4r docs recommend one logger per class. Does that mean in each
class I have to create a @log variable to hold a reference to the
logger? Can't I just have a $log variable, or will multiple threads
collide?

I really like the look of the local log statement,

log.warn "Oh, no!"

but it looks like I'll have to use @log.warn or $log.warn.

And that reminds me of a thread question. Are mutexes needed only for
writing? In other words, if I have a hit counter that's being
incremented, @hits, and the only thing changing the value is one
method in the class in which @hits lives, is it OK to have a show_hits
method that returns @hits or does it have to be mutexed?
 
P

Peter C. Verhage

John said:
but it looks like I'll have to use @log.warn or $log.warn.

Maybe you could create a simple Module for it and include it in every
class where you need a logger. Then you could simply implement a log
method in the Module which would return the log instance.

Regards,

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,135
Messages
2,570,784
Members
47,342
Latest member
KelseyK737

Latest Threads

Top