GWT: how to write client side logs into a log file in GWT

倖福魔咒の 提交于 2019-12-25 17:18:40

问题


HI guys i am facing a big problem to write logs in a file in GWT.

i ahd gone through all the posts over internet but i didn't find any valuable information there.

What i did ...

  1. added remote logging servlet in web.xml file
  2. inherited the logging module in my .gwt.xml file.

But my question is here now suppose i have written one log in my Entry Point class.

like ....

//Main class to start the appliation.....


public void onModuleLoad() {

    Logger logger=Logger.getLogger(SYTMain.class.getName());

    logger.info("Test Log in Module File");
}

and now i want to write this client side log into a test.log file .

How i can achieve this???/

Please if anyone knows the answer then plz provide me the complete solution, i don't want example on a fly. if you really know then only plz tell me don't give the answer which is already available in net.....

mY delivery date is very near so plz update on same ASAP, i'll be very thankful to you.


回答1:


In your module file add the following:

  <inherits name='com.google.gwt.logging.Logging'/>
  <set-property name="gwt.logging.enabled" value="TRUE"/>
  <!-- Set logging level to INFO -->
  <set-property name="gwt.logging.logLevel" value="INFO"/>
  <set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
  <!-- Add compiler.stackMode to get a readable stacktrace from JavaScript 
       It generates a set of files in WEB-INF/deploy; those files need to
       be placed on the server
    -->
  <set-property name="compiler.stackMode" value="emulated" />

In your web.xml add the following:

 <servlet>
    <servlet-name>remoteLoggingService</servlet-name>
    <servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl</servlet-class>
</servlet>

<!-- Servlet Mapping -->
<servlet-mapping>
    <servlet-name>remoteLoggingService</servlet-name>
    <url-pattern>/<your module name>/remote_logging</url-pattern>
</servlet-mapping>

Replace <your module name> with as it says your module name.

To log simply use the code as your mentions. Use the import from java.util.logging.




回答2:


On the client side, GWT compiles to Javascript, and Javascript cannot in general write files to the client's filesystem. (It should be obvious why this could be a bad idea). See for example this discussion.

If what you need is logs to use for debugging, one obvious solution is to have the logger append to a text area on the page. You can always copy and past manually into another file. Or, if you want to debug remotely, you could have the logger write to the server.




回答3:


Just create a RPC service to log it into the server-side.

Use the servlet-side threadlocal to get info about the client: ThreadLocal to store ServletRequest and Response in servlet: what for?.



来源:https://stackoverflow.com/questions/9444218/gwt-how-to-write-client-side-logs-into-a-log-file-in-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!