Ognjen Blagojevic | 1 Sep 11:02 2008
Picon

Re: HOw to replace the system.out.println

MY POI wrote:
> Dear all
> 
>            I want to use the logging system in my Project which consist of
> many modules developing by the 
> 
> much developers. Here I need to replace system.out.println statements and i
> want put loggers.
> 
> Is there any way to configuring one property file to replace the statements.
> 
> Many thanks in advance
> Rajesh

At the beginning of every class you should put:

   private static Logger logger = Logger.getLogger(ClassName.class);

Than, instead of

   System.out.println("...");

use

   logger.logMethod("...")

where logMethod is info/warning/debug etc.

In the end, put log4j.properties in the src.folder:

(Continue reading)

MY POI | 2 Sep 14:34 2008
Picon

Re: HOw to replace the system.out.println


Thanks a lot..but here we are having hundreads of classes..

in this case any solution is there

thanks

Ognjen Blagojevic wrote:
> 
> MY POI wrote:
>> Dear all
>> 
>>            I want to use the logging system in my Project which consist
>> of
>> many modules developing by the 
>> 
>> much developers. Here I need to replace system.out.println statements and
>> i
>> want put loggers.
>> 
>> Is there any way to configuring one property file to replace the
>> statements.
>> 
>> Many thanks in advance
>> Rajesh
> 
> At the beginning of every class you should put:
> 
>    private static Logger logger = Logger.getLogger(ClassName.class);
> 
(Continue reading)

Michael Erskine | 2 Sep 15:57 2008

RE: HOw to replace the system.out.println

MY POI [mailto:vrkrajeshraju <at> yahoo.co.in] wrote:
> Subject: Re: HOw to replace the system.out.println
> Thanks a lot..but here we are having hundreads of classes..
> in this case any solution is there

I'd use Awk or Perl to make the edits for me.

If you don't want to make any edits then you have plenty of options! You can redirect standard output (and
perhaps standard error) with System.setOut() (and System.setErr()) to a new PrintStream that will
perform log4j logging! I use this technique quite regularly to adapt libraries and code that write to
stdout/stderr (with judicious buffering and filtering of course!)

Regards,
Michael Erskine.
Thorbjørn Ravn Andersen | 2 Sep 17:34 2008
Picon

Re: HOw to replace the system.out.println

MY POI skrev  den 02-09-2008 14:34:
> Thanks a lot..but here we are having hundreads of classes..
>
> in this case any solution is there
>   
This might help you getting started:

helpers/FooBar.java
=====
package helpers;

public class FooBar {
    public static void main(String[] args) {
        System.out.println("Hello World");
        System.out.println("Hello World");
        org.slf4j.LoggerFactory.getLogger(Me.callerClass()).info("Hello 
World");
        org.slf4j.LoggerFactory.getLogger(Me.callerClass()).info("Hello 
World");
    }
}
=====

helpers/Me.java
====
package helpers;

public class Me {

    public static String callerClass() {
(Continue reading)

David Britton | 2 Sep 18:02 2008
Picon

Re: single line to diffrent log file

On Sat, Aug 30, 2008 at 05:21:51PM +0000, praveen#123 wrote:
> 
> 
> can any one healp me
>  to log single line to a diffrent log file and all other logs of the same
> class to the other log file

I only know of two straightforward ways to do this:

1) Create two loggers which could then do whatever you want... for
instance:

  com.foo.myclass
  com.foo.myclass.SPECIAL

You could then log the "special" line to it's own log file by attaching
a new appeneder to the special category, and it would also bubble up to
its the real appender if that is so desired.  This would require code
modification, of course.

2) You could potentially do this without modification as well...  If
there is a string in the log message that is unique enough, you can use
a filter:

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/Filter.html

--

-- 
David Britton
Curt Arnold | 2 Sep 19:01 2008
Picon

Re: HOw to replace the system.out.println


On Sep 2, 2008, at 10:34 AM, Thorbjørn Ravn Andersen wrote:

> MY POI skrev  den 02-09-2008 14:34:
>> Thanks a lot..but here we are having hundreads of classes..
>>
>> in this case any solution is there
>>
> This might help you getting started:
>
> helpers/FooBar.java
> =====
> package helpers;
>
> public class FooBar {
>   public static void main(String[] args) {
>       System.out.println("Hello World");
>       System.out.println("Hello World");
>        
> org.slf4j.LoggerFactory.getLogger(Me.callerClass()).info("Hello  
> World");
>        
> org.slf4j.LoggerFactory.getLogger(Me.callerClass()).info("Hello  
> World");
>   }
> }

The suggestion introduces SLF4J into the mix with explanation and  
goes  through a lot of effort to evaluate the class of the calling  
statement for categorization when the cost might be excessive.  It  
(Continue reading)

Thorbjørn Ravn Andersen | 2 Sep 19:36 2008
Picon

Re: HOw to replace the system.out.println

Curt Arnold skrev  den 02-09-2008 19:01:
>
> The suggestion introduces SLF4J into the mix with explanation and 
> goes  through a lot of effort to evaluate the class of the calling 
> statement for categorization when the cost might be excessive.  It 
> would seem that if you replaced the System.println(...) with a call to 
> something like:
There are many ways to skin a cat.

Your suggestion is simple but throws away all location information.  My 
suggestion is more complex (admitted, the slf4j was a spinal reflex in 
the material I dug up for this) and slow, but keeps location information

The stack trace investigation is necessary when doing a simple 
text-replace as you do not know if you are inside a static method. 

Perhaps a long term effort in this regard, could be developing an 
Eclipse/Netbeans/Whatever refactoring template which converts 
System.out/System.err references to log statements?

--

-- 
  Thorbjørn Ravn Andersen          "... plus... Tubular Bells!"
Curt Arnold | 2 Sep 19:42 2008
Picon

Re: HOw to replace the system.out.println


On Sep 2, 2008, at 12:36 PM, Thorbjørn Ravn Andersen wrote:

> Curt Arnold skrev  den 02-09-2008 19:01:
>>
>> The suggestion introduces SLF4J into the mix with explanation and  
>> goes  through a lot of effort to evaluate the class of the calling  
>> statement for categorization when the cost might be excessive.  It  
>> would seem that if you replaced the System.println(...) with a call  
>> to something like:
> There are many ways to skin a cat.
>
> Your suggestion is simple but throws away all location information.   
> My suggestion is more complex (admitted, the slf4j was a spinal  
> reflex in the material I dug up for this) and slow, but keeps  
> location information

I believe you could still extract it if you wanted it, but it keeps it  
all in one place and you can decide if you want to go to that  
expense.  You could also check the threshold of the logger hierarchy  
before attempting to determine the location.
Patrick.Grimard | 2 Sep 21:00 2008

DEBUG messages appearing on console?


I'm trying to configure log4j so that DEBUG messages or lower priority only
appear in a log file and not the console, and anything above DEBUG appears on
the console.  This is what my log4j.properties file looks like right now,
however the DEBUG messages are still appearing on the console.  I'm using log4j
along with Commons Logging API if that makes any difference.

# Set the root logger to the INFO level and CA to be it's appender
log4j.rootLogger=WARN, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss} [%t]
%c%n\t{%m}%n%n

# LinkHarvester
log4j.logger.com.dsn.loadlink=DEBUG, harvester
log4j.appender.harvester=org.apache.log4j.RollingFileAppender
log4j.appender.harvester.File=C:/log4j/logs/LinkHarvester.log
log4j.appender.harvester.MaxFileSize=100KB
log4j.appender.harvester.MaxBackupIndex=1
log4j.appender.harvester.layout=org.apache.log4j.PatternLayout
log4j.appender.harvester.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss}
[%t] %c%n\t{%m}%n%n
(Embedded image moved to file: pic18467.jpg)
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe <at> logging.apache.org
For additional commands, e-mail: log4j-user-help <at> logging.apache.org
David Britton | 2 Sep 21:31 2008
Picon

Re: DEBUG messages appearing on console?

On Tue, Sep 02, 2008 at 07:00:22PM +0000, Patrick.Grimard <at> xtl.com wrote:
> 
> I'm trying to configure log4j so that DEBUG messages or lower priority only

Please see the following answer I recently gave:

  http://mail-archives.apache.org/mod_mbox/logging-log4j-user/200808.mbox/%3C20080825151619.GA13754 <at> dune.americas.cpqcorp.net%3E

--

-- 
David Britton <dpb <at> hp.com>

Gmane