Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 61
  1. #21
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    CJSL, first of all, I'll post my code segment use in the past for debugging later. I don't have any backup on that.

    The way you suggest is much better. But for me it's a mess, as I said earlier. It cause to have more line of code which only useful in development process, not for the actual process. So reading more and more number of code lines are really mess for me, and for others may be.

    My best choice is separate class, simply import it in to any class where I want to have a log, and use singleton on that log class.

  2. #22
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    CJSL, you gave away the ans so fast, and its not even a friday.
    Anyways, I done some test with logger. And I have to say, i'm loving it. It's almost the same as using print statements but with different levels. It shows the calling class and method, plus date/time.

    Here's the test code:
    Java Code:
    import java.util.logging.*;
    
    public class LoggerExample {
       public static void main (String[] args) {
          Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
    
          int n = 5;
          logger.log(Level.SEVERE,"The value for n is: "+n);
          logger.log(Level.WARNING,"The value for n is: "+n);
          logger.log(Level.INFO,"The value for n is: "+n);
          logger.log(Level.CONFIG,"The value for n is: "+n);
          logger.log(Level.FINE,"The value for n is: "+n);
          logger.log(Level.FINER,"The value for n is: "+n);
          logger.log(Level.FINEST,"The value for n is: "+n);
          
          // display end of program
          System.out.print("END");
       }
    }
    Here's the first run with default logging.properties values.
    Java Code:
    S:\tmp>java LoggerExample
    Jan 20, 2009 9:34:51 PM LoggerExample main
    SEVERE: The value for n is: 5
    Jan 20, 2009 9:34:51 PM LoggerExample main
    WARNING: The value for n is: 5
    Jan 20, 2009 9:34:51 PM LoggerExample main
    INFO: The value for n is: 5
    END
    To see all logging's, you need to edit the file "C:\Program Files\Java\jre6\lib\logging.properties".
    LINE29: .level= INFO
    LINE43: java.util.logging.ConsoleHandler.level = INFO


    Change "INFO" to: ALL

    Here's the run after changing INFO to ALL:
    Java Code:
    S:\tmp>java LoggerExample
    Jan 20, 2009 9:28:32 PM LoggerExample main
    SEVERE: The value for n is: 5
    Jan 20, 2009 9:28:32 PM LoggerExample main
    WARNING: The value for n is: 5
    Jan 20, 2009 9:28:32 PM LoggerExample main
    INFO: The value for n is: 5
    Jan 20, 2009 9:28:32 PM LoggerExample main
    CONFIG: The value for n is: 5
    Jan 20, 2009 9:28:32 PM LoggerExample main
    FINE: The value for n is: 5
    Jan 20, 2009 9:28:32 PM LoggerExample main
    FINER: The value for n is: 5
    Jan 20, 2009 9:28:32 PM LoggerExample main
    FINEST: The value for n is: 5
    END
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #23
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #24
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    I read that it's suppose to be in the user's home folder. (I couldn't find mine.) But you can use FileHandler to change it to maybe C:\temp.log or whatever. This class is still new to me.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  5. #25
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #26
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Quote Originally Posted by Eranga View Post
    Yes, the thing is I've never use this in my applications. log4j is the one I'm using.
    Whatever works for you man. Its all part of the Java logging framework.

    Here's what wiki has to say:
    Quote Originally Posted by http://en.wikipedia.org/wiki/Java_Logging_Frameworks
    Of the major players, log4j is still the front runner in the Java Logging domain[citation needed]. The log4j project has been around for a long time and has lots of support from the development community. It's simple to implement, yet has powerful tools built in to accomplish most logging tasks. It is also easily extensible to handle proprietary needs.


    The Jakarta Commons Logging isn't really a logging framework, but a logging framework wrapper. As such, it requires a logging framework underneath it. It would be useful in an heterogeneous environment where the logging framework is likely to change. However, in most cases, once a suitable logging framework has been chosen, there is little need to change it over the life of the project.

    The Java Logging API is also not a logging framework, but standard API for accessing a logging framework. Compatible frameworks can be loaded into JVM and accessed via the API. There is also a logging implementation supplied with the Sun JVM which is the default logging framework access by the API. Many developers confuse this implementation with the Java Logging API.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  7. #27
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by angryboy View Post
    Whatever works for you man. Its all part of the Java logging framework.
    That's true. But the thing is I directly get familiar with log4j. You know when I looking to choose an separate logger in my application, my supervisor advice me to choose the log4j. He says that what you exactly pointed here.

  8. #28
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    eranga, prob w/ using log4j for debugging is that you need to have the api download/installed in the first place. meaning its not as portable. where as Logger comes w/ jre.

    I agree w/ erange that the print debug method is a mess. I alway strip out the print statements in my final code so it'll run faster. But I've found something interesting about assertions. read this:

    Quote Originally Posted by core_java
    Enabling or disabling assertions is a function of the class loader. When assertions are disabled, the class loader strips out the assertion code so that it won't slow execution.
    Does this mean I can use alot of assertions in my code w/o taking it out? Would this make assertions a better choice for debugging than print statements? whats your pov on this?

    Also, how does the JVM handle branch predictions? does it always assume true or false or some other algorithm? if true, then wouldn't it be better to inverse the logic? like this:

    boolean debug = true;
    ...
    if (!debug) ...
    Last edited by angryboy; 01-21-2009 at 08:33 PM.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  9. #29
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Java assert...

    I haven't finished reviewing Java asserts, but it appears to modify the program flow. For example, if an assert gets activited, it gets caught and throws the appropiate exception... the code doesn't continue after an assert is activited. This is no good as a debugger.

    Have to keep investigating...

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  10. #30
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I know! I know!

    Step 1. Download Netbeans
    Step 2. Install Netbeans
    ...

  11. #31
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    steve, you are off topic. the ? is how do you debug w/o ide.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  12. #32
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Nope. My ! to the ? is: get one

  13. #33
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by angryboy View Post
    eranga, prob w/ using log4j for debugging is that you need to have the api download/installed in the first place. meaning its not as portable. where as Logger comes w/ jre.
    Yes setting up the log4j and use it for debugging is need to do bit of work. But once get more familiar with that, easy to carry on.

  14. #34
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default hahaha...

    Steve... yeah I know and agree. I thought that it would be cool to start a thread about debbuging techniques and see what happened. New comers to the language would probably find it useful (learning a prog lang and an IDE at the same time can be frustrating). Therefore they can learn how to debug their programs manually and later use the IDE's debugger. Just a thought...

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  15. #35
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    hey, it is cool. it got me motivated on reading up about Logger, assertion, and jdb. These are normally really boring stuff to me.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  16. #36
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Talking various

    @ Steve, I did - never got so mad in ten years of trying to write code. They have one goal: SLOW...sloww.....sssss......lllllll......ooooo.... ....wwwwwwwww
    ( insert massive empty space here)better to dye at Winchester Cathedral as undocumented golfer than let that thing take it's Toll. See ide password does not match ide password....
    Java Code:
    [HKEY_LO
    "\\??\\V
      30,01,
    "\\??\\V
      00,00,
    "\\??\\V
    what's the point of letting these broken knees subvert the free?

    @xcallmejudasx: poor man's editor ...define poor.

    @CJSLMAN hahaha....just a thought - more than just a thought.

    @ angryboy steve, you are off topic. the ? is how do you debug w/o ide. how debug when IDE never let write code? Launch IDE, got to lunch. Get back, write five or ten lines of code. Later that afternoon, most of the inane code practices are implemented to where the code will compile. Get confident, run code. Next day, get notice from untraceable electronic traffic about "latest software" .... machine ruint trying to get rid of it. Dig into code with an actual text editor, discover code archaeology, contemplate visitor pass to The Body Farm.

    @angryboy
    Java Code:
    boolean debug = true;
    read Addison-Wesley Professional series, there is a Ph.D. with field experience writing in that series that this is to be the preferred method of debugging. Any non-trivial compiler will remove these statements from the code passed to the compiler. I assume that Java will Load the Kitchen Sink, fouty megs of heap and who knows ... gonna try Micro-Edition soon. See if it will reduce the footprint of Legacy.

    @angryboy
    Whatever works for you man. Its all part of the Java logging framework.
    I browsed the site of that, very competent tool. Approach is to look into what that person did.

    @angryboy CJSL, you gave away the ans so fast, and its not even a friday. My company motto: "Is it Friday yet?" which is to be recited upon awakening Saturday Morning. Those who wish to make a contest of it may see how close they can get to 12:00 without being mired in the 12:00 is am or pm issue.
    @CJSLMAN I am surprised at all the answers received. Why? And what do you do when field-deployment keps mixing up the grammar of ops manual ....?
    Last edited by Nicholas Jordan; 01-22-2009 at 02:48 PM.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  17. #37
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Has no one mentioned JUnit? Of course, most people not using an IDE are probably not ready for that...

  18. #38
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Is that JUnit related with this topic? Just use it for testing, or performance testings right? Not for debugging a code.

  19. #39
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Steve... yeah I know and agree. I thought that it would be cool to start a thread about debbuging techniques and see what happened. New comers to the language would probably find it useful (learning a prog lang and an IDE at the same time can be frustrating). Therefore they can learn how to debug their programs manually and later use the IDE's debugger. Just a thought...
    I think this thread is great. I just can't resist making jokes. The fact is, even with a debugger, I've been reduced to println statements scattered through 80 source members because I couldn't figure out how the threads were interacting (*I* didn't write that code, I inherited it.)

    And now, for the ultimate solution!!!

    Post your code on Java Forums and let someone else do it!

    Sorry...

  20. #40
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    4
    Rep Power
    0

    Default

    Hi all, i m a new joinee to this forum.. and found some intresting query..which seems to be silly but really not so.. :) ..

    I suggest to use a method which takes a parameter and which prints stmts( System.out.print) .. so that you can call this method wherever you want your code to be debugged.. it makes easy to on/off the debugging, just commenting the print stmt in the method..

    if u didnt get wht i was trying to say or if i confused u, with my stupid english.. look at the code snippet..

    public class debugWithOutIDE{

    public void printValue(Object oValue){
    System.out.println(oValue.toString());

    }


    public void processMehtod(){
    String sValue = "saikumar komati";
    printValue(sValue);
    sValue = "New memeber";
    printValue(sValue);
    sValue = "Java Forum";
    printValue(sValue);

    }

    }

Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Java Debug Interface
    By jbabe in forum Advanced Java
    Replies: 2
    Last Post: 09-02-2008, 06:04 AM
  2. Not able to debug simple hello world program
    By amit123solanki in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 04:41 PM
  3. Java Debug Level
    By keshari in forum New To Java
    Replies: 1
    Last Post: 05-26-2008, 09:23 AM
  4. how to debug the servlet
    By tommy in forum Java Servlet
    Replies: 1
    Last Post: 08-06-2007, 09:53 PM
  5. how to debug java code in eclipse
    By rajesh058 in forum Advanced Java
    Replies: 3
    Last Post: 07-26-2007, 12:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •