RE: Unable to display caller name in log info

2008-06-16 Thread Bender Heri
The FQCN is used for determinating the class which issued the log call.
The log framework produces a callstack and searches backwards until it
has found the supplied FQCN. The next entry is then taken for expanding
the %C pattern in the layout.

Normally, if you use the myLogger.debug() (et al.) methods, the Logger
class inserts its own FQCN on calling the generic method. That's why the
calling class will show up in the rendered log message. Make use of the
generic method log() only if you use a centralized log wrapper class.
Then you would supply the FQCN of that wrapper class in order to render
the name of the class which has called the wrapper.

Your example supplies a file name as FQCN. This string cannot be found
within the stack trace, so the routine climbs up until the main method
of the main class. Nothing found -> "?".

If you want to see "LogTest" as %C replacement, you have to supply
LogText.getClass().getName() as FQCN.

Heri

> -Original Message-
> From: Debarshi Sanyal [mailto:[EMAIL PROTECTED] 
> Sent: Monday, June 16, 2008 8:42 AM
> To: log4j-user@logging.apache.org
> Subject: [SPAM (DNS Blacklist)] - Unable to display caller 
> name in log info - Sending mail server found on list.dsbl.org
> 
> Hi,
> 
> I wrote a small Java program to configure an 
> org.apache.log4j.Logger and log messages using it.
> 
> Excerpts from the Java file are:
> 
> package MyPackage;
> 
> //...
> 
> public class LogTest
> {
> private static Hashtable cLoggerHash = new Hashtable();
> private void setLogInfo()
> {
> String sLogFile = "TestLogFile.log";
> Logger cLogger = Logger.getLogger( sLogFile );
> cLogger.setLevel( Level.toLevel("DEBUG") );
> PatternLayout cLayout = new PatternLayout();
> cLayout.setConversionPattern( "[%d{/MM/dd 
> HH:mm:ss.SSS}]%C -
> %m%n" );
> 
> 
> RollingFileAppender cFileAppender = new RollingFileAppender();
> //...
> cFileAppender.activateOptions( );
> cFileAppender.setLayout( cLayout );
> cLogger.addAppender( cFileAppender );
> cLoggerHash.put( sLogFile, cLogger );
>}
>public static void main (String[] args)
>{
>LogTest logTest = new LogTest();
>logTest.setLogInfo();
>Logger cLogger = Logger.getLogger( "TestLogFile.log" );
>cLogger.log("TestLogFile.log", Level.INFO,  "\t 
> ++ This is a test log + ", null);
> 
>}
> 
> The output is:
> [2008/06/13 20:24:53.415]? - ++ This is a test log
> +
> 
> 
> The fully qualified classname is NOT displayed.
> Instead a "?" is displayed.
> 
> Please help.
> 
> Regards,
> Debarshi
> 

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



Re: Unable to display caller name in log info

2008-06-16 Thread Jacob Kjome
First, it's unusual to name your logger after the name of the log file you 
expect it to go to.  But I guess that's up to you.  Your real problem is 
probably that you haven't compile your classes with debug info (the java -g 
option).


Jake


On Mon, 16 Jun 2008 12:11:37 +0530
 "Debarshi Sanyal" <[EMAIL PROTECTED]> wrote:

Hi,

I wrote a small Java program to configure an org.apache.log4j.Logger and log
messages using it.

Excerpts from the Java file are:

package MyPackage;

//...

public class LogTest
{
   private static Hashtable cLoggerHash = new Hashtable();
   private void setLogInfo()
   {
   String sLogFile = "TestLogFile.log";
   Logger cLogger = Logger.getLogger( sLogFile );
   cLogger.setLevel( Level.toLevel("DEBUG") );
   PatternLayout cLayout = new PatternLayout();
   cLayout.setConversionPattern( "[%d{/MM/dd HH:mm:ss.SSS}]%C -
%m%n" );


   RollingFileAppender cFileAppender = new RollingFileAppender();
   //...
   cFileAppender.activateOptions( );
   cFileAppender.setLayout( cLayout );
   cLogger.addAppender( cFileAppender );
   cLoggerHash.put( sLogFile, cLogger );
  }
  public static void main (String[] args)
  {
  LogTest logTest = new LogTest();
  logTest.setLogInfo();
  Logger cLogger = Logger.getLogger( "TestLogFile.log" );
  cLogger.log("TestLogFile.log", Level.INFO,  "\t ++ This
is a test log + ", null);

  }

The output is:
[2008/06/13 20:24:53.415]? - ++ This is a test log
+


The fully qualified classname is NOT displayed.
Instead a "?" is displayed.

Please help.

Regards,
Debarshi



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



Re: Unable to display caller name in log info

2008-06-17 Thread Debarshi Sanyal
Hi,
Thanks for the response. Using fully qualified class name as the first
parameter to cLogger.log() fixes the issue.

Regards,
Debarshi

On 6/16/08, Jacob Kjome <[EMAIL PROTECTED]> wrote:
>
> First, it's unusual to name your logger after the name of the log file you
> expect it to go to.  But I guess that's up to you.  Your real problem is
> probably that you haven't compile your classes with debug info (the java -g
> option).
>
> Jake
>
>
> On Mon, 16 Jun 2008 12:11:37 +0530
>  "Debarshi Sanyal" <[EMAIL PROTECTED]> wrote:
>
>> Hi,
>>
>> I wrote a small Java program to configure an org.apache.log4j.Logger and
>> log
>> messages using it.
>>
>> Excerpts from the Java file are:
>>
>> package MyPackage;
>>
>> //...
>>
>> public class LogTest
>> {
>>   private static Hashtable cLoggerHash = new Hashtable();
>>   private void setLogInfo()
>>   {
>>   String sLogFile = "TestLogFile.log";
>>   Logger cLogger = Logger.getLogger( sLogFile );
>>   cLogger.setLevel( Level.toLevel("DEBUG") );
>>   PatternLayout cLayout = new PatternLayout();
>>   cLayout.setConversionPattern( "[%d{/MM/dd HH:mm:ss.SSS}]%C -
>> %m%n" );
>>
>>
>>   RollingFileAppender cFileAppender = new RollingFileAppender();
>>   //...
>>   cFileAppender.activateOptions( );
>>   cFileAppender.setLayout( cLayout );
>>   cLogger.addAppender( cFileAppender );
>>   cLoggerHash.put( sLogFile, cLogger );
>>  }
>>  public static void main (String[] args)
>>  {
>>  LogTest logTest = new LogTest();
>>  logTest.setLogInfo();
>>  Logger cLogger = Logger.getLogger( "TestLogFile.log" );
>>  cLogger.log("TestLogFile.log", Level.INFO,  "\t ++ This
>> is a test log + ", null);
>>
>>  }
>>
>> The output is:
>> [2008/06/13 20:24:53.415]? - ++ This is a test log
>> +
>>
>>
>> The fully qualified classname is NOT displayed.
>> Instead a "?" is displayed.
>>
>> Please help.
>>
>> Regards,
>> Debarshi
>>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>