Another possible way to log client side in GWT is to use console.log method of java script.
As in GWT all client side code is converted into Java script we can add native java script method it self on the client side to print log.
Follow belwo given step to do the same.
Step 1: Add follwoing lines in your *.gwt.xml.
Step 2:- Create a class Named as DebugClientSide inside client folder.
package com.test.client;
public class DebugClientSide {
private static boolean isEnabledFlag_ = false;
public static void enable() { isEnabledFlag_ = true; }
public static void setEnabled( final boolean isEnabledFlag )
{ isEnabledFlag_ = isEnabledFlag; }
public static void log( final String s )
{ if( isEnabledFlag_ ) nativeConsoleLogMehod( s ); }
private static native void nativeConsoleLogMehod( String s )
/*-{ console.log( s ); }-*/;
}
Step 3:- Put following line on the client side class to see the console log
Debug.enable();
Debug.log("This is client side console log");
After execution you can see your client side log in console as shown below.
As in GWT all client side code is converted into Java script we can add native java script method it self on the client side to print log.
Follow belwo given step to do the same.
Step 1: Add follwoing lines in your *.gwt.xml.
Step 2:- Create a class Named as DebugClientSide inside client folder.
package com.test.client;
public class DebugClientSide {
private static boolean isEnabledFlag_ = false;
public static void enable() { isEnabledFlag_ = true; }
public static void setEnabled( final boolean isEnabledFlag )
{ isEnabledFlag_ = isEnabledFlag; }
public static void log( final String s )
{ if( isEnabledFlag_ ) nativeConsoleLogMehod( s ); }
private static native void nativeConsoleLogMehod( String s )
/*-{ console.log( s ); }-*/;
}
Step 3:- Put following line on the client side class to see the console log
Debug.enable();
Debug.log("This is client side console log");
After execution you can see your client side log in console as shown below.
No comments:
Post a Comment