You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Boris Lipsman <b_...@yahoo.com> on 2006/07/10 19:44:23 UTC

log4j extra level problem

Hi,

This is what I have done:
   Step1: Created MyLevelClass ( extends LEVEL ) with 2 extra levels declared
                TRACE and METHOD_DEBUG_DETAILS
   Step2: Created the wrapper around Logger ( log4j)
   Step3: Added to the log4j.xml the following 
            
  <appender name="TRACE_APP_LOG" class="org.apache.log4j.FileAppender">
            <param name="File" value="${jboss.server.log.dir}/TraceApp.log"/>
            <param name="Append" value="false"/>
           
            <layout class="org.apache.log4j.PatternLayout">
               <!-- The TRACEPCSDBLOG pattern: -->
               <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
      
            </layout>
 </appender>


   Step4: Defined the category that referencing the appender
    <category name="com.mywebapp">
           <priority value="TRACE" class="com.mywebapp.logging.MyExtraLevel" />
           <appender-ref ref="TRACE_APP_LOG" />
   </category>


   While, I start JBoss, all looks good, the trace level is beaing created(
      I used to get before error messages that 
com.mywebapp.logging.MyExtraLevel is not found. But that was fixed by adding 
jar to the lib directory.

 here is the scenario:
      MyLogger  myLogger = new MyLogger(SomeClass.class);
      // MyLogger is a wrapper around Logger ( log4j)

      myLogger.trace(); 
      // trace() is actually calling generic log() method of the log4j
      Strange thing, when I call the trace() method the message does not go 
anywhere.

Please help

Boris


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


my owen loggerclass

Posted by Strasser Christoph <ch...@vinzenzgruppe.at>.
hi,

 

i need to write an owen logger class extending log4js logger and
overwriting the debug, info, warn, error and fatal methods!

 

o.k. - i've done it like that:

 

public void debug(Object msg){

...

my operations

...

 

logger.debug(msg);  //logger is an object of log4js Logger

}

 

the problem is... i'm configuring my logger object in a properties file,
and i need to track the calling class and method (the methode who starts
the logging)... 

 

i used the patternlayouts litterals %C{1}.%M for getting the Class and
Methods names... but now MY appender is the calling class and my debug
method is the calling method... due to the command 

logger.debug(msg);  //logger is an object of log4js Logger

 

:(((

 

i've tried to replace the logger.debug(msg) thing with the code, that is
in the Logger.debug methode - hoping to get the initialli calling class
and methode... getting Nullpointers because of repository is Null... i
tryed get rid of this problem by setting the repository... but now... my
loggerobject doesnt have an appender... but it should have one... here
is the fragment of my code - can anyone help me with this?!?!

 

public void debug(Object msg){

            

...

my operations

...         

 

Logger logger = Logger.getLogger("myAppender");

 

Hierarchy hierarchy = new Hierarchy(logger);

repository = hierarchy;

      

if (repository.isDisabled(Level.DEBUG_INT)) {

  return;

}

 

if (Level.DEBUG.isGreaterOrEqual(logger.getEffectiveLevel())) {

  forcedLog(myLogger.class.getName(), Level.DEBUG, msg, null);

}

}


Re: log4j extra level problem

Posted by jaikiran pai <ja...@yahoo.co.in>.
I had a look at the code of log4j and here's what it does in the log method, which you are calling:
   
  ---------------------
  /**
    This generic form is intended to be used by wrappers.
 */
  public
  void log(Priority priority, Object message) {
    if(repository.isDisabled(priority.level)) {
      return;
    }
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
      forcedLog(FQCN, priority, message, null);
  }
  --------------------------
   
  And here's the implementation of priority.isGreaterOrEqual method:
   
  /**
     Returns <code>true</code> if this level has a higher or equal
     level than the level passed as argument, <code>false</code>
     otherwise.  
     
     <p>You should think twice before overriding the default
     implementation of <code>isGreaterOrEqual</code> method.
    */
  public
  boolean isGreaterOrEqual(Priority r) {
    return level >= r.level;
  }
   
  What's the integer value that you have given to your Level, that you created?
  If this method returns false, then your message wont be logged to the file.
   
  regards,
  -Jaikiran
   
   
   
   
   
   
   
  

Boris Lipsman <b_...@yahoo.com> wrote:
  Hi,

This is what I have done:
Step1: Created MyLevelClass ( extends LEVEL ) with 2 extra levels declared
TRACE and METHOD_DEBUG_DETAILS
Step2: Created the wrapper around Logger ( log4j)
Step3: Added to the log4j.xml the following 
















Step4: Defined the category that referencing the appender







While, I start JBoss, all looks good, the trace level is beaing created(
I used to get before error messages that 
com.mywebapp.logging.MyExtraLevel is not found. But that was fixed by adding 
jar to the lib directory.

here is the scenario:
MyLogger myLogger = new MyLogger(SomeClass.class);
// MyLogger is a wrapper around Logger ( log4j)

myLogger.trace(); 
// trace() is actually calling generic log() method of the log4j
Strange thing, when I call the trace() method the message does not go 
anywhere.

Please help

Boris


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org



 				
---------------------------------
 Find out what India is talking about on  Yahoo! Answers India.
 So, whatÂ’s NEW about the NEW Yahoo! Messenger? Find out.