Logging with GWT
23 Sep 2016
- First, modify our module configuration file (X.gwt.xml) where X is the class which holds the EntryPoint of your application.
<pre><inherits name=”com.google.gwt.logging.Logging” />
<set-property name=”gwt.logging.logLevel” value=”INFO”/>
<set-property name=”gwt.logging.enabled” value=”TRUE”/>
<set-property name=”gwt.logging.consoleHandler” value=”ENABLED”/>
<set-property name=”gwt.logging.popupHandler” value=”DISABLED” /><!– Disable PopupLogHandler –>
<set-property name=”gwt.logging.simpleRemoteHandler” value=”DISABLED” /></pre>
3. In your class, import the library.
4. Then, instantiate the logger with whatever name, possibly with the class name to make it more descriptive.
public Logger logger = Logger.getLogger(“MyClassLogger”);
5. Then it can be used anywhere within it’s scope. Examples :
logger.log(Level.SEVERE, “Connection refused: “);
logger.log(Level.INFO, “Query executed : “ + executedQuery);
6. The log levels define the severity of a message. The Level class is used to define which messages should be written to the log. You can set the minimum level by the following :
7. These are the typical usage of these levels :
ERROR: Any error/exception that is or might be critical.
WARN: Any message that might warn us of potential problems, e.g. when a user tried to log in with wrong credentials - which might indicate an attack if that happens often or in short periods of time
INFO: Anything that we want to know when looking at the log files, e.g. when a scheduled job started/ended.