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 Vani Bandargal <va...@hotmail.com> on 2009/04/16 16:05:21 UTC

Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Is there any way to output the log statemts from a particular method to a
different log file other than what is configued for that package?

In other words a 2 log files for a package. First log file for some methods
and the second one is for other methods.

<p>

Ex:  package com.foo.p1

public class Tset{

private metgod 1{
//log should output in Log File1
}

private metgod2{
//log should output in Log File2
}


}

</p>
-- 
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23078688.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Matt Brown <Ma...@citrixOnline.com>.
http://logging.apache.org/log4j/1.2/manual.html Take a look at the section on Appender Additivity.

 

-----Original Message-----
From: Vani Bandargal [mailto:vanims_98@hotmail.com] 
Sent: Thursday, April 16, 2009 1:18 PM
To: log4j-user@logging.apache.org
Subject: RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?


Matt, Incredible...Thanks for helping me out. 

 I can now see the database1 log file contains log from method1 and
database2
log file contains log from method2. 

On a side note(not a big deal)both logs from method1 and method2 are outputted in root log too(along with what is specified) Is there any way to stop it outputting in root log. 

Thanks.

--
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23082558.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


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


RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Vani Bandargal <va...@hotmail.com>.
Matt, Incredible...Thanks for helping me out. 

 I can now see the database1 log file contains log from method1 and
database2 
log file contains log from method2. 

On a side note(not a big deal)both logs from method1 and method2 are
outputted in root log too(along with what is specified) Is there any way to
stop it outputting in root log. 

Thanks.

-- 
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23082558.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Matt Brown <Ma...@citrixOnline.com>.
You have this configuration:

	log4j.logger.package1.delegate=ERROR, database1
	log4j.logger.package1.delegate=ERROR, database2

Yet with this code, you are using the loggers named "databaselog1" and "databaselog2":

	private static Logger logger1 = Logger.getLogger("databaselog1"); 
	private static Logger logger2 = Logger.getLogger("databaselog2");

So you should be configuring it like this

	log4j.logger.databaselog1=ERROR, database1
	log4j.logger.databaselog2=ERROR, database2

But also, if you only configure the logger to log at ERROR level, then when you log with log.info() in the actual source code, this INFO level message will be ignored, since it falls below the threshold.

For your testing, try

	log4j.logger.databaselog1=ALL, database1
	log4j.logger.databaselog2=ALL, database2 

-----Original Message-----
From: Vani Bandargal [mailto:vanims_98@hotmail.com] 
Sent: Thursday, April 16, 2009 12:31 PM
To: log4j-user@logging.apache.org
Subject: RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?


I have attched the log4J properties file and a sample delegate that I used.

Please take a look. Appreciate if you point out what I am missing.

All my log statements are printed in root.log. They are neither going to
databaselog1 and nor to databaselog2
http://www.nabble.com/file/p23081601/Log4J.properties.txt
Log4J.properties.txt 

http://www.nabble.com/file/p23081601/SampleDelegate.txt SampleDelegate.txt
--
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23081601.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


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


RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Vani Bandargal <va...@hotmail.com>.
Incredible...Thanks for helping me out.

 I can now see the database1 log file contains log from method1 and
database2
log file contains log from method2.

On a side note(not a big deal)both logs from method1 and method2 are
outputted in root log too(along with what is specified) Is there any way to
stop it outputting in root log.

Thanks.
-- 
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23082542.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Vani Bandargal <va...@hotmail.com>.
I have attched the log4J properties file and a sample delegate that I used.

Please take a look. Appreciate if you point out what I am missing.

All my log statements are printed in root.log. They are neither going to
databaselog1 and nor to databaselog2
http://www.nabble.com/file/p23081601/Log4J.properties.txt
Log4J.properties.txt 

http://www.nabble.com/file/p23081601/SampleDelegate.txt SampleDelegate.txt 
-- 
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23081601.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Matt Brown <Ma...@citrixOnline.com>.
The point of using two different names is that then it allows you to configure these two loggers differently in your configuration (either log4j.xml or log4j.properties or whatever other method you are using to configure log4j).

If you give the loggers two different names, but they are still being treated the same, that means that you have not updated your configuration to treat these two loggers differently. 

-----Original Message-----
From: Vani Bandargal [mailto:vanims_98@hotmail.com] 
Sent: Thursday, April 16, 2009 10:57 AM
To: log4j-user@logging.apache.org
Subject: Re: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?



yaog wrote:
> 
> In the log4j file add different logger definitions for MyLogger1 and 
> MyLogger2.
> 

you mean In log4J.properties or in log4J.xml?


yaog wrote:
> 
> He means this:
> 
> 
> public class OfflineMethodsDelegate extends BaseDelegate {
> 
>        private static Logger logger1 = 
> Logger.getInstance("MyLogger1");
> 
>        private static Logger logger2 = 
> Logger.getInstance("MyLogger2");
> 
> 
> 
> public void method1(UserInfo uInfo)throws DAOException {
>                logger1.debug("This is Method 1 Log");
> 
>        }
> 
> public void method2(UserInfo uInfo)throws DAOException {
>                logger2.debug("This is Method 2 Log");
> 
>        }
> 
> }
> 
> 
> 
Is not it the name given in Logger.getInstance is just arbitarary name and no mattter what iou give , it will be written to the same file configured?
--
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23079687.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


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


Re: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Yair Ogen <ya...@gmail.com>.
same thing.

On Thu, Apr 16, 2009 at 5:57 PM, Vani Bandargal <va...@hotmail.com>wrote:

>
>
> yaog wrote:
> >
> > In the log4j file add different logger definitions for MyLogger1 and
> > MyLogger2.
> >
>
> you mean In log4J.properties or in log4J.xml?
>
>
> yaog wrote:
> >
> > He means this:
> >
> >
> > public class OfflineMethodsDelegate extends BaseDelegate {
> >
> >        private static Logger logger1 = Logger.getInstance("MyLogger1");
> >
> >        private static Logger logger2 = Logger.getInstance("MyLogger2");
> >
> >
> >
> > public void method1(UserInfo uInfo)throws DAOException {
> >                logger1.debug("This is Method 1 Log");
> >
> >        }
> >
> > public void method2(UserInfo uInfo)throws DAOException {
> >                logger2.debug("This is Method 2 Log");
> >
> >        }
> >
> > }
> >
> >
> >
> Is not it the name given in Logger.getInstance is just arbitarary name and
> no mattter what iou give , it will be written to the same file configured?
> --
> View this message in context:
> http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23079687.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Vani Bandargal <va...@hotmail.com>.

yaog wrote:
> 
> In the log4j file add different logger definitions for MyLogger1 and
> MyLogger2.
> 

In log4J.properties or in log4J.xml?


yaog wrote:
> 
> He means this:
> 
> 
> public class OfflineMethodsDelegate extends BaseDelegate {
> 
>        private static Logger logger1 = Logger.getInstance("MyLogger1");
> 
>        private static Logger logger2 = Logger.getInstance("MyLogger2");
> 
> 
> 
> public void method1(UserInfo uInfo)throws DAOException {
>                logger1.debug("This is Method 1 Log");
> 
>        }
> 
> public void method2(UserInfo uInfo)throws DAOException {
>                logger2.debug("This is Method 2 Log");
> 
>        }
> 
> }
> 
> 
> 
Is not it the name given in Logger.getInstance is just arbitarary name and
no mattter what iou give , it will be written to the same file configured?
-- 
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23079687.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Yair Ogen <ya...@gmail.com>.
He means this:


public class OfflineMethodsDelegate extends BaseDelegate {

       private static Logger logger1 = Logger.getInstance("MyLogger1");

       private static Logger logger2 = Logger.getInstance("MyLogger2");



public void method1(UserInfo uInfo)throws DAOException {
               logger1.debug("This is Method 1 Log");

       }

public void method2(UserInfo uInfo)throws DAOException {
               logger2.debug("This is Method 2 Log");

       }

}


In the log4j file add different logger definitions for MyLogger1 and
MyLogger2.


On Thu, Apr 16, 2009 at 5:27 PM, Vani Bandargal <va...@hotmail.com>wrote:

>
> Matt, I am providing code based on what I understood from your suggestion.
>
> Do you mean to do this?
>
> public class OfflineMethodsDelegate extends BaseDelegate {
>        private static Logger logger1 =
> Logger.getInstance(OfflineMethodsDelegate.class);
>        private static Logger logger2 =
> Logger.getInstance(OfflineMethodsDelegate.class);
>
>
>
> public void method1(UserInfo uInfo)throws DAOException {
>                logger1.debug("This is Method 1 Log");
>
>        }
>
> public void method2(UserInfo uInfo)throws DAOException {
>                logger2.debug("This is Method 2 Log");
>
>        }
>
> }
>
>
>
> Vani Bandargal wrote:
> >
> > Thank you Matt.
> > Could you Please eloborate on what you are suggesting?
> >
> > Are you referring to name given in Logger.getLogger() method.
> >
> > I tried this. Is not it it is just a name of logger object and no  matter
> > you give 2 different names, it will write to the same log file configured
> > for that package.
> > Thanks for any tips
> >
>
> --
> View this message in context:
> http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23079102.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Vani Bandargal <va...@hotmail.com>.
Matt, I am providing code based on what I understood from your suggestion.

Do you mean to do this?

public class OfflineMethodsDelegate extends BaseDelegate {   
	private static Logger logger1 =
Logger.getInstance(OfflineMethodsDelegate.class);
	private static Logger logger2 =
Logger.getInstance(OfflineMethodsDelegate.class);
	
	

public void method1(UserInfo uInfo)throws DAOException {
		logger1.debug("This is Method 1 Log");
		
	}

public void method2(UserInfo uInfo)throws DAOException {
		logger2.debug("This is Method 2 Log");
		
	}

}



Vani Bandargal wrote:
> 
> Thank you Matt.
> Could you Please eloborate on what you are suggesting?
> 
> Are you referring to name given in Logger.getLogger() method.
> 
> I tried this. Is not it it is just a name of logger object and no  matter
> you give 2 different names, it will write to the same log file configured
> for that package.
> Thanks for any tips
> 

-- 
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23079102.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Vani Bandargal <va...@hotmail.com>.
Thank you Matt.
Could you Please eloborate on what you are suggesting?

Are you referring to name given in Logger.getLogger() method.

I tried this. Is not it it is just a name of logger object and no  matter
you give 2 different names, it will write to the same log file configured
for that package.
Thanks for any tips


Matt Brown-20 wrote:
> 
> A pretty simple solution would be to have each method use two different
> Logger objects (with different names).
> 

-- 
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23079003.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


RE: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

Posted by Matt Brown <Ma...@citrixOnline.com>.
A pretty simple solution would be to have each method use two different Logger objects (with different names).

-----Original Message-----
From: Vani Bandargal [mailto:vanims_98@hotmail.com] 
Sent: Thursday, April 16, 2009 10:05 AM
To: log4j-user@logging.apache.org
Subject: Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?


Is there any way to output the log statemts from a particular method to a different log file other than what is configued for that package?

In other words a 2 log files for a package. First log file for some methods and the second one is for other methods.

<p>

Ex:  package com.foo.p1

public class Tset{

private metgod 1{
//log should output in Log File1
}

private metgod2{
//log should output in Log File2
}


}

</p>
--
View this message in context: http://www.nabble.com/Is-there-any-way-to-output-the-log-statemts-from-a-particular-method-to-a-different-log-file-other-than-what-is-configued-for-that-package--tp23078688p23078688.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


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