You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Yeroc <cp...@gmail.com> on 2006/12/11 18:08:33 UTC

SessionLog annoyance

Hello...

First of all, thanks for the great work on Mina.  I've just started using it
on a small project and am finding it quite useful.  

There is one thing that annoys me and that is logging.  The SessionLog class
logs all messages using the Logger classname of my IoHandler.  This presents
a problem for me in that I can no longer differentiate log messages emitted
from the SessionLog class versus log messages emitted from my own IoHandler
class.  Furthermore, I can't filter the log messages emitted by SessionLog
(which are generally less useful to me) without also filtering the logging
output from my own IoHandler class.

The only workaround I can see is to use a different Logger name for my
IoHandler class but the problem is that our standard is to always use the
classname as the Logger -- changing it to something else will just create
confusion.

Would the developers consider modifying the SessionLog class to use some
other name for the Logger?

Thanks,
Corey

-- 
View this message in context: http://www.nabble.com/SessionLog-annoyance-tf2795367.html#a7798780
Sent from the mina dev mailing list archive at Nabble.com.


Re: SessionLog annoyance

Posted by Corey Puffalt <cp...@gmail.com>.
Thanks for your reply.  I had looked at the source code but for some reason
it hadn't occurred to me that I could override the default by setting the
session attributes. :P

Corey

On 12/11/06, Niklas Therning <ni...@trillian.se> wrote:
>
> Yeroc wrote:
> > Hello...
> >
> > First of all, thanks for the great work on Mina.  I've just started
> using it
> > on a small project and am finding it quite useful.
> >
> > There is one thing that annoys me and that is logging.  The SessionLog
> class
> > logs all messages using the Logger classname of my IoHandler.  This
> presents
> > a problem for me in that I can no longer differentiate log messages
> emitted
> > from the SessionLog class versus log messages emitted from my own
> IoHandler
> > class.  Furthermore, I can't filter the log messages emitted by
> SessionLog
> > (which are generally less useful to me) without also filtering the
> logging
> > output from my own IoHandler class.
> >
> > The only workaround I can see is to use a different Logger name for my
> > IoHandler class but the problem is that our standard is to always use
> the
> > classname as the Logger -- changing it to something else will just
> create
> > confusion.
> >
> > Would the developers consider modifying the SessionLog class to use some
> > other name for the Logger?
> >
> >
> You can change the name of the logger used by SessionLog in your
> IoHandler's sessionCreated() like this:
>
> public void sessionCreated(IoSession session) {
>     session.setAttribute(SessionLog.LOGGER,
> LoggerFactory.getLogger("my.logger"));
>     session.setAttribute(SessionLog.PREFIX, "[" +
> session.getRemoteAddress() + "] ");
> }
>
> See the source code of SessionLog for more info on how it works:
>
> http://svn.apache.org/viewvc/mina/tags/1.0.1/core/src/main/java/org/apache/mina/util/SessionLog.java?view=markup
> If you look at this code you will understand why you must set the prefix
> yourself if you change the logger.
>
> There's also an issue in JIRA which deals with the LoggingFilter and
> SessionLog. Setting the name of the logger and the prefix will be a lot
> easier in MINA 2.0:
>
> http://issues.apache.org/jira/browse/DIRMINA-314
>
> HTH
>
> --
> Niklas Therning
> www.spamdrain.net
>
>

Re: SessionLog annoyance

Posted by Niklas Therning <ni...@trillian.se>.
Yeroc wrote:
> Hello...
>
> First of all, thanks for the great work on Mina.  I've just started using it
> on a small project and am finding it quite useful.  
>
> There is one thing that annoys me and that is logging.  The SessionLog class
> logs all messages using the Logger classname of my IoHandler.  This presents
> a problem for me in that I can no longer differentiate log messages emitted
> from the SessionLog class versus log messages emitted from my own IoHandler
> class.  Furthermore, I can't filter the log messages emitted by SessionLog
> (which are generally less useful to me) without also filtering the logging
> output from my own IoHandler class.
>
> The only workaround I can see is to use a different Logger name for my
> IoHandler class but the problem is that our standard is to always use the
> classname as the Logger -- changing it to something else will just create
> confusion.
>
> Would the developers consider modifying the SessionLog class to use some
> other name for the Logger?
>
>   
You can change the name of the logger used by SessionLog in your
IoHandler's sessionCreated() like this:

public void sessionCreated(IoSession session) {
    session.setAttribute(SessionLog.LOGGER,
LoggerFactory.getLogger("my.logger"));
    session.setAttribute(SessionLog.PREFIX, "[" +
session.getRemoteAddress() + "] ");
}

See the source code of SessionLog for more info on how it works:
http://svn.apache.org/viewvc/mina/tags/1.0.1/core/src/main/java/org/apache/mina/util/SessionLog.java?view=markup
If you look at this code you will understand why you must set the prefix
yourself if you change the logger.

There's also an issue in JIRA which deals with the LoggingFilter and
SessionLog. Setting the name of the logger and the prefix will be a lot
easier in MINA 2.0:

http://issues.apache.org/jira/browse/DIRMINA-314

HTH

-- 
Niklas Therning
www.spamdrain.net