无法在Google App Engine上使用Log4j编写日志文件

时间:2015-01-21 17:20:00

标签: java google-app-engine log4j

我正在尝试log4j。我在控制台中输出了打印输出。但是当我尝试使用FileAppender时,它会显示错误。 我使用的是谷歌应用引擎。 这是我的代码。

package com.log4jtest;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.*;

import org.apache.log4j.Appender;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;

@SuppressWarnings("serial")
public class Log4jTestServlet extends HttpServlet  
{

  int count=0;
  private static Logger log=Logger.getLogger(Log4jTestServlet.class);
  public void doGet(HttpServletRequest req, HttpServletResponse resp)throws      IOException 
  {
     resp.setContentType("text/plain");

    /*BasicConfigurator.configure();*/
    Appender app=new FileAppender(new SimpleLayout(),"hello.log");
    log.setLevel(Level.TRACE);
    BasicConfigurator.configure(app);
    PrintWriter out=resp.getWriter();

    //private static Logger log=Logger.getLogger(Log4jTestServlet.class);
    String username="faisal";
    String password="mohamed";

    //int count=0;

    count++;
    out.println(count);
    log.trace("TRACE");
    log.debug("DEBUG");
    log.info("INFO");
    log.warn("WARN");
    log.error("ERROR");
    log.fatal("FATAl");


    System.out.println("end line of the program");
    resp.getWriter().println("Hello, world");
  }
 }

这是我的错误..

Http error 500
 java.io.FileOutputStream is a restricted class. Please see the Google  App Engine developer's guide for more details.

现在我要做什么

1 个答案:

答案 0 :(得分:1)

请参阅对此的回答:Does Google App Engine allow creation of files and folders on the server? 你不能在GAE上写文件。使用控制台或Log API