Hello everyone,


I am wondering how to remove debug information (for example, System.out or System.err) automatically when I build/compile a Java project? Does Java compiler or build tool has such options when we build/compile a Java application?


Thanks in advance,
George

Recommended Answers

All 14 Replies

I don't recall anything like that. I would either leave them, or remove them manually.

You can't, and you don't want to.

Once your application ships you want to be able to get some logs when there's a problem at a customer's site.

To get that build your application to log those messages to some file.
If you create a logger with different logging levels you can turn on different levels of logging at runtime by changing a config file or command line option.

Java has (from 1.4 onwards) a quite comprehensive logging framework built in, or you can use a 3rd party framework like Log4J.

Logfiles should at the minimum list a timestamp with every entry so you can trace what happened where, and best also a very good indication of where the entry was created (just using this.toString() is a good start, line numbers can help as well).

I had no clue you could do that in java. I looked at some of the logging api's, and it looked very useful.

Thanks all the same, server_crash. ;)

I don't recall anything like that. I would either leave them, or remove them manually.

regards,
George

Thanks jwenting,

You can't, and you don't want to.

Once your application ships you want to be able to get some logs when there's a problem at a customer's site.

To get that build your application to log those messages to some file.
If you create a logger with different logging levels you can turn on different levels of logging at runtime by changing a config file or command line option.

Java has (from 1.4 onwards) a quite comprehensive logging framework built in, or you can use a 3rd party framework like Log4J.

Logfiles should at the minimum list a timestamp with every entry so you can trace what happened where, and best also a very good indication of where the entry was created (just using this.toString() is a good start, line numbers can help as well).

Your reply is very helpful. I have learned so much dealing with log from you. Can you recommend some online resources to learn log related topics?


regards,
George

Thanks server_crash,

I had no clue you could do that in java. I looked at some of the logging api's, and it looked very useful.

I am wondering how you debug your applications since you do not use log utility.


regards,
George

Oh, there's System.out.println() which is what everyone used before dedicated loggers became available.
We created our own logging API, another favourite passtime in days past.

Thanks server_crash,


I am wondering how you debug your applications since you do not use log utility.


regards,
George

lol I never really did. Sometimes I used System.out.println()'s, and sometimes I just knew what to do from the error. I've never really created anything so big, that it require a lot of debugging. But, my text editor I'm working on right now is in need of it. So I might have to put it to some use.

Thanks for providing information server_crash,

lol I never really did. Sometimes I used System.out.println()'s, and sometimes I just knew what to do from the error. I've never really created anything so big, that it require a lot of debugging. But, my text editor I'm working on right now is in need of it. So I might have to put it to some use.

regards,
George

Thanks jwenting,

Oh, there's System.out.println() which is what everyone used before dedicated loggers became available.
We created our own logging API, another favourite passtime in days past.

Your reply is very helpful. I am wondering what special features can your logging API achieve which System.out.println() can not achieve?


regards,
George

hmm, what about automatically adding timestamps and fixed formatting, multithreaded writing to a file, consistent formatting of arrays written to the log, etc. etc.

Thanks jwenting,

hmm, what about automatically adding timestamps and fixed formatting, multithreaded writing to a file, consistent formatting of arrays written to the log, etc. etc.

I think your tookit is very great since it has so many features. I hope you can share your tookit in the future. :mrgreen:


regards,
George

sorry, it's proprietary to the company.
But it's not hard to create something similar with a bit of thinking :)

Thanks for all the people who helped me on this thread.


regards,
George

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.