【问题标题】:running tinylog inside glassfish在 glassfish 中运行 tinylog
【发布时间】:2012-09-08 10:03:02
【问题描述】:

我正在尝试在 glassfish 3.1.2.2 中运行 tinylog。首先,我将 tinylog.jar 复制到 /glassfish3/glassfish/domains/domain1/lib。其次,我在domain1/config 中创建了tinylog.propertiestinylog.properties是这样的:

tinylog.format={date}-[{class}:{method}:{line}]-{level}-{message}
tinylog.writer=rollingfile
tinylog.writer.filename=log.txt
tinylog.writer.backups=5
tinylog.writer.label=count
tinylog.writer.policies=size: 10KB

我的应用程序是这样一个简单的网络服务:

@WebService
public class Calculator {
    @WebMethod
    public int sum(int a, int b) {
        Logger.info("new request. a = {0}, b = {1}", a, b);
        return a + b;
    }
}

现在,当我运行 Web 服务时,它可以工作并返回结果。但日志在logs/server.log 中,如下所示:

[#|2012-09-08T14:15:03.801+0430|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=175;_ThreadName=Thread-2;|2012-09-08 14:15:03 [http-thread-pool-8080(1)] com.argengco.tiny.Calculator.sum()
INFO: new request. a = 43, b = 7
|#]

由于默认情况下tinylog将日志写入stdout,glassfish将stdout重定向到javax.enterprise.system.std.com.sun.enterprise.server.logging记录器,看来tinylog没有找到tinylog.properties。我在server.log 中看不到任何权限错误,这表明它无法打开tinylog.properties。谁能帮忙?

【问题讨论】:

    标签: java logging glassfish tinylog


    【解决方案1】:

    如果 /glassfish3/glassfish/domains/domain1 是您的源构建树的根(即它包含 com/blah/blah),那么您需要:

    1) 将 tinylog.properties 文件放在该目录中

    2) 致电PropertiesLoader.loadFromFile("config/tinylog.properties");

    在尝试自己找到答案后,我遇到了您的问题。在使用一些调试消息(有点讽刺!)重建源代码后,我找到了答案。

    就我而言,我有一个 src/com/blah/blah 目录结构。在这种情况下,tinylog.properties 文件需要放在 src/ 目录中。

    【讨论】:

      猜你喜欢
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多