gpt4 book ai didi

java - 有没有办法在 GAE GWT 应用程序中登录文件?

转载 作者:行者123 更新时间:2023-12-01 13:40:27 25 4
gpt4 key购买 nike

我是 GAE GWT 应用程序的新手。我正在开发一个 GAE - GWT 应用程序,使用 spring MVC 3 作为服务提供者,GWT 作为 UI 客户端(我不习惯使用 GWT 的 RPC 概念,所以我开始使用 spring)和 log4j (v1.2.17) & log4j-gwt-1.0`用于记录。现在我需要在文件中记录“日志”。

但是在编码时,似乎 GWT 接受 ConsoleAppender但不是 FileAppenderRollingFileAppender .

如何在 GWT 中配置 log4j 以将“(服务器)日志”记录在单独的文件中?

我的 log4j.properties 文件

# A default log4j configuration for log4j users.
#
# To use this configuration, deploy it into your application's WEB-INF/classes
# directory. You are also encouraged to edit it as you like.

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# Configure the console as our one appender
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n
log4j.appender.A1.File=/logger.log
log4j.appender.A1.MaxFileSize=10MB
# Keep one backup file
log4j.appender.A1.MaxBackupIndex=1


# tighten logging on the DataNucleus Categories
log4j.category.DataNucleus.JDO=WARN, A1
log4j.category.DataNucleus.Persistence=WARN, A1
log4j.category.DataNucleus.Cache=WARN, A1
log4j.category.DataNucleus.MetaData=WARN, A1
log4j.category.DataNucleus.General=WARN, A1
log4j.category.DataNucleus.Utility=WARN, A1
log4j.category.DataNucleus.Transaction=WARN, A1
log4j.category.DataNucleus.Datastore=WARN, A1
log4j.category.DataNucleus.ClassLoading=WARN, A1
log4j.category.DataNucleus.Plugin=WARN, A1
log4j.category.DataNucleus.ValueGeneration=WARN, A1
log4j.category.DataNucleus.Enhancer=WARN, A1
log4j.category.DataNucleus.SchemaTool=WARN, A1
和我的代码片段。

import org.apache.log4j.Logger;
final private static Logger LOGGER = Logger.getLogger("RegistrationController");

异常(exception) :


java.lang.NoClassDefFoundError: java.io.FileOutputStream is a restricted class. Please see the Google  App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:842)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:768)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:648)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:514)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:580)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:526)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
at org.apache.log4j.Logger.getLogger(Logger.java:104)
at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:262)
at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:108)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:127)
at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:135)
at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1025)
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:844)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:541)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:292)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:671)
at org.springframework.web.servlet.DispatcherServlet.<clinit>(DispatcherServlet.java:246)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:249)
at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:306)
at com.google.appengine.tools.development.AutomaticInstanceHolder.startUp(AutomaticInstanceHolder.java:26)
at com.google.appengine.tools.development.AbstractModule.startup(AbstractModule.java:79)
at com.google.appengine.tools.development.Modules.startup(Modules.java:88)
at com.google.appengine.tools.development.DevAppServerImpl$2.run(DevAppServerImpl.java:383)
at com.google.appengine.tools.development.DevAppServerImpl$2.run(DevAppServerImpl.java:376)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.appengine.tools.development.DevAppServerImpl.restart(DevAppServerImpl.java:376)
at com.google.appengine.tools.development.gwt.AppEngineLauncher$AppEngineServletContainer.refresh(AppEngineLauncher.java:51)
at com.google.gwt.dev.DevMode.onRestartServer(DevMode.java:349)
at com.google.gwt.dev.shell.remoteui.RemoteUI.restartWebServer(RemoteUI.java:166)
at com.google.gwt.dev.shell.remoteui.DevModeServiceRequestProcessor.processRestartServer(DevModeServiceRequestProcessor.java:94)
at com.google.gwt.dev.shell.remoteui.DevModeServiceRequestProcessor.execute(DevModeServiceRequestProcessor.java:59)
at com.google.gwt.dev.shell.remoteui.MessageTransport.processClientRequest(MessageTransport.java:362)
at com.google.gwt.dev.shell.remoteui.MessageTransport.processMessage(MessageTransport.java:404)
at com.google.gwt.dev.shell.remoteui.MessageTransport.access$400(MessageTransport.java:44)
at com.google.gwt.dev.shell.remoteui.MessageTransport$3.run(MessageTransport.java:322)
at java.lang.Thread.run(Thread.java:724)
log4j:WARN No appenders could be found for logger (org.springframework.web.servlet.DispatcherServlet).

有没有办法将日志记录在文件而不是控制台中?
如果没有,一旦在 GAE 中部署,如何获取控制台日志?

最佳答案

在我看来,您有更大的问题然后登录。首先 GWT 和 GAE 是两个不同的东西。 GWT 是用 Java 构建 JavaScript 应用程序的工具包,GAE 是服务器端框架。所以当你说 I am not comfortable using GWT's RPC concept, so I started using spring在我看来,你好像还没有完全理解发生了什么。 Spring 在服务器上运行,在浏览器中运行 GWT 应用程序。为了在浏览器和服务器之间进行通信,GWT 有 RPC 为此,它负责浏览器和服务器之间的通信。 Spring 仅在服务器上运行,因此不会帮助您在浏览器中的 GWT 应用程序和服务器之间进行通信。所以你的评论对我来说就像一个危险信号。

所以继续记录。这个故事有两个方面。

首先登录服务器,或者在GAE中。 GAE 有自己的日志记录。见 ( https://developers.google.com/appengine/docs/java/?csw=1#Java_Logging )。这里的简短回答是,在使用 log4j 时,您需要将其配置为记录到 stdout 和 stderr。 stackoverflow 上有几个关于如何配置它的问题( https://stackoverflow.com/questions/tagged/google-app-engine+log4j )。

其次,如果您想在部署后查看 GWT 日志,技术上的意思是,您将日志从浏览器发送回服务器,然后在服务器上将它们放入服务器的标准日志中。幸运的是,GWT 开箱即用地支持此功能,您需要做的就是启用远程日志记录。在您的 gwt.xml 文件中添加以下行:

<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />

有关 GWT 日志记录和远程日志记录的更多信息,请参阅: http://www.gwtproject.org/doc/latest/DevGuideLogging.html#Remote_Logging

关于java - 有没有办法在 GAE GWT 应用程序中登录文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20844121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com