At 05:41 AM 10/15/2006, you wrote:
>Hi Jacob,
>thanks for your reply.
>
>Checking in the log4j source code, i saw all log methods and all guard
>methods performs something like this:
>
>    public boolean isTraceEnabled() {
>        if (repository.isDisabled(Level.TRACE_INT)) {
>            return false;
>          }
>
>          return Level.TRACE.isGreaterOrEqual(this.getEffectiveLevel());
>    }
>
>The repository level is set to ALL by default, so just overriding
>getEffectiveLevel() i'm able to have a per user level.
>
>I developed my Logger and my LoggerFactory. The LoggerFactory is needed
>just to create and return instances of my Logger.
>My Logger has just two methods:
>
>   public
>    Level getEffectiveLevel() {
>      Level userLevel = getUserLevel((String)MDC.get("userName"));
>      if (userLevel != null) {
>          return userLevel;
>      }
>      for(Category c = this; c != null; c=c.getParent()) {
>        if(c.getLevel() != null)
>          return c.getLevel();
>      }
>      return null; // If reached will cause an NullPointerException.
>    }
>
>    private Level getUserLevel(String userName) {
>         return _the_user_level;
>    }
>
>
>This way seems to work fine, but does anyone see some
>issue/problem/drawback ?
>

Other than the fact that you can't just plug the behavior in without extension, it looks like a decent solution. And, normally, it is recommended that Logger be wrapped than extended. Search the archives for reasoning. But, if it works for you, that's great! I'd be interested in being able to configure this in a standard way in the long run.

Jake

>Thanks a lot
>Ste
>
>>
>> Jake
>>
>> >Any help will is appreciated.
>> >Thanks in advance.
>> >
>> >Ste
>> >
>> >
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to