How can I avoid unwanted log messages in a java project?

In my java project I have a bunch of lines externalized in a file messages.properties

. In the corresponding file Messages.java

, I had the same number of public static String attributes that I could access these external texts.

Then I implemented a method called getString

that takes the name of the constant as an argument and returns the required text. This way, there is no need to declare all public static attributes with lines in the file Messages.java

.

But after that my journal was filled with "NLS unused message" messages.

Do you know if there is a way to prevent these warning messages from being recorded?

Thanks in advance.

0


source to share


3 answers


Posts sounds like the class you wrote because I don't see it in the javadocs of JDK 6.

It looks like you were trying to rethink java.util.ResourceBundle. I would recommend using that instead and dropping your class. This will have the added benefit of properly handling the I18N.



I don't see any value in hardcoding the public static message keys in the class. This is another thing that you will have to maintain. If I understand what you are doing right, I would throw away your posts and use ResourceBundle instead.

+3


source


Your class Messages

- looks like it extends org.eclipse.osgi.util.NLS

.

If so, it is designed to fill the requirements:

  • to ensure a compile-time check that the message exists.
  • to avoid using map memory containing both keys and values ​​(this will be the case in the resource bundle approach).
  • good support for i18n.


i.e. NLS fills importance Message.staticVariable

value staticVariable

found in messages.properties.

The warning log contains information about inconsistencies between files Messages.java

and messages.properties

.

Your method getString()

sounds like it doesn't take advantage of any NLS benefits, since others have suggested you might be better off using a ResourceBundle.

+5


source


duffymo , as jamesh said, Messages

is a class I wrote and it continues org.eclipse.osgi.util.NLS

. It has a private static attribute, and its type is ... ResourceBundle!

jamesh , thanks for a detailed description of how NLS works.

As per your answers, I removed my class Messages

from my project and added an attribute with a ResourceBundle attribute for classes that need to use external strings. Also, I did it so that the lines referring to the outer lines don't need to be changed.

The number of files in our project was reduced, the code was kept as clean as before, and there were no more log warnings.

Thanks guys. You rock.

0


source







All Articles