Wooten, Bryan wrote:

Gee, I didn't mean to be a smart ass. Please accept my apologies. You
seemed to need guidance on how to debug a "java server" program.
Hi there, I was kidding. I will see what's the output and get back soon.

I still stand by the 3 pieces of advice I gave you:
those are 4 peices:

1. What do the Fedora utilities say about the socket you've opened? 2. What does an ethereal trace look like between the client and server?
3. Hook up that remote debugger and find out exactly what your program
is doing.
4. Get log4j or some other logging system implemented.

Bryan


-----Original Message-----
From: Mansour [mailto:[EMAIL PROTECTED] Sent: Thursday, September 07, 2006 1:24 PM
To: Log4J Users List
Subject: Re: Is't that useless?? may be I don't understand

Wooten, Bryan wrote:

I usually don't jump into these threads, but this time I can't help
myself.

A couple of questions:

1. What is the host OS?  Most (all) OSes have utilities to help
diagnose
sockets and connections.


Fedora 4, the server running on Fedora 3.


2. What is your development environment?  Eclipse? JBuilder?


Eclipse. But this has nothign to do with my code, as I pack it into jar and send it to the server.

3. How are you handling exceptions?  A simple printStackTrace() can
explain many issues.


I guess I mentioned in my first message, there was no error or exception. My first message stated clearly that I am getting no error. I

wrote my first message during the 21 century. How come you foregot, this

info.

4. You say your project is a "java server", I assume that means there
is
some other program that sends/ recvs to your socket.  What is that
program doing?  When programming sockets, it is almost a necessity to
use etherreal (or similar) to monitor network traffic.


There's nothing wrong with the client program, it's sending the packets with no problem, so the issue , I am having is with the server.

And last comment, this is the 21st century, java has both local and
remote source level debugging, you need to learn to set that up and use
it.


My Last comment, thatnk you for letting me know what century we are at. And thank you for being concern about what I should know and what I shouldn't . Back again to my original message, I stated that "I am newbie to log4j and I am looking for quick way". If I were you, I would put somehting useful into the thread, or I will learn to jump out again,

and stop trying to be smart A**.

Debugging using printf or logging is tedious and sometimes ineffective.
Regardless, using a logging utility like log4j is a very good idea.

Good luck and happy programming.

Bryan

-----Original Message-----
From: Mansour [mailto:[EMAIL PROTECTED] Sent: Thursday, September 07, 2006 12:46 PM
To: Log4J Users List
Subject: Re: Is't that useless?? may be I don't understand

David Tonhofer wrote:



Mansour wrote:

Hi Everybody:
I am writing a java server project and got to the point where the program stops and hangs there with no error it just does nothing. I decided to go ahead and learn how to use log4j, to be able to see what's going on and for my future projects. However through all the documentaion I have came accros, I found no single usefull example for a beginner. One of the sockets in my program is stuck there not sending and not recieving, and I am trying


to find out what's wrong without modifying the code for my project. If I have to go and modify the code, adding something similar to print statements like logger.debug and logger.info as teh examples show, then log4j is the most useless thing I came across. I am not expecting in any way to do somehting like this. Here's a piece of code that I was able to add to my main method, but again nothign useful came out.

static Logger lgr1 = Logger.getLogger("Joint");
BasicConfigurator.configure();
lgr1.setLevel(Level.DEBUG);
lgr1.info("This is from logger lgr1");
lgr1.debug("This is from logger lgr1");

Please not that, It's urgent and I can not at this point use any of the extra classes or layers. All I need is the basic information about th erunning program. Any advice ??

YODA SAYS:

Adding logging statements to your program is NEVER useless because they are a form of auto-documentation and debugging aid. The difference with System.out.println being evidently that you can switch


them off if you do not need them and switch them on again if it misbehaves. Then you can push the output to files, sockets, a database, swing applications etc. etc. Any source code that you come accross that has no logging statements should immediately get a couple


of demerit
points. Additionally, any source code that you come accross that has no assert() statements and input verifications should get a few additional demerit points.

YODA ALSO SAYS:

It is not good to be in a hurry when you debug socket handling code.


Now, ro get the logging to work:

1) Initialize inside main() or someplace where you are sure to pass:

     //
     // add layout and appender to root category
     //
     {
         Layout layout = new TTCCLayout();
Logger.getRootLogger().addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT));
         Logger.getRootLogger().setLevel(Level.DEBUG);
     }

This will cause your program to log to the console, and accepts all messages down to DEBUG

2) Group your message sources into conceptual sources, aka. 'Loggers'.


A good idea is to call your Loggers by the
name of the method in which they appear. For example, in you class 'Main':

public class Main {

 static final private String CLASS = Main.class.getName();
static final private Logger LOGGER_allocateWatchdogServerSocket = Logger.getLogger(CLASS + ".allocateWatchdogServerSocket");

 public static ServerSocket allocateWatchdogServerSocket() {
     Logger logger = LOGGER_allocateWatchdogServerSocket;
     logger.debug("Going to allocate now");
          // BLAH BLAH
     if (initBunch.getServerPort() == 0) {
logger.info("Watchdog's port is 0 - it will be chosen randomly");
     }
      // BLAH BLAH
     }
 }






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

Thank you david for your help:
So what you mean is to go modify my code and insert log statements whereever I need. I'll try. Now back again to your code, seems deep. I am gonna try to understand what have you done, then I 'll get back to you.




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


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





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


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



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

Reply via email to