• Post Reply Bookmark Topic Watch Topic
  • New Topic

Logger classes  RSS feed

 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From reading on the Sun website, I have understood that Lohgger class is used to send messages to the console.
Can you give me an example code for the following?
Is there some website where I can get some examples on understanding and writing Logging statements?
I have the following classes-
package test;
public class MainClass
{
public static void main(String args[])
{
System.out.println("Hello world");
SubClass sub = new SubClass();
sub.add();
}
}
class Sub
{
public void add()
{
int a= 1, b=2;
int sum = a + b;
System.out.println("this is the sum"+ sum);
}
}
 
Scott Stoddard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the code you have provided does not really lend itself well to an example for logging, as it would be essentially redundant.
Usually I use the logger class like this:

The gist of this being that anything passed to the info method will print to stdout (unless logging is turned off - it's on by default).
To turn it off you would use:

Hope this helps!
 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!