让码头以正确的时区记录日志 [英] Getting jetty to log with the correct timezone

查看:115
本文介绍了让码头以正确的时区记录日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jetty 8,并正在配置我的jetty.xml以自定义request.log文件.

I'm using Jetty 8 and am configuring my jetty.xml to customise the requests.log files.

我的问题是,Jetty正在使用格林尼治标准时间(GMT)时区的时间戳来提供日志-我在英国,但现在是夏令时(GMT + 1,又名BST).可能是因为:

My problem is, Jetty is serving the logs with a timestamp in the GMT timezone - I'm in the UK but its now summer time (GMT+1, aka, BST). Probably because of:

<Set name="LogTimeZone">GMT</Set>

我如何让Jetty使用服务器上的本地时间(正确)来提供日志? 仅仅删除<Set name="LogTimeZone">GMT</Set>并没有任何作用,而且我也不必每6个月手动更改一次.

How do I get Jetty to serve the logs using whatever the local time on the server is (which is correct)? Simply removing the <Set name="LogTimeZone">GMT</Set> didn't do anything, and I don't want to have to manually change it every 6ish months.

谢谢

推荐答案

Jetty NCSARequestLog使用

The Jetty NCSARequestLog uses java.util.TimeZone.

GMT是NCSA格式的日志文件的默认设置,因为这是各种日志分析工具所期望的.

GMT is the default for NCSA formatted log files, as this is what various log analysis tools expects.

这听起来像您希望NCSA格式的日志使用夏令时敏感的时区.在这种情况下,您实际上只有一种选择,请使用适合您的系统和环境的长格式时区.

It sounds like you want the NCSA formatted logs to use a timezone that is daylight savings aware. In that case you have really 1 choice, use the long format Timezone appropriate for your system and environment.

以下是有关英国伦敦的详细信息: http://www.timeanddate.com/worldclock/city .html?n = 136

Here's the details about London, England: http://www.timeanddate.com/worldclock/city.html?n=136

您需要的是将由系统标识的TimeZone字符串.意思是:

What you need is a TimeZone string that will identified by your system. Which means:

  • TimeZone标识符不使用GMT偏移量表示法
  • TimeZone标识符不是3个字母(请参阅有关字母时区ID" )
  • TimeZone标识符是长格式.

创建一个简单的Java源文件,并在您的系统上运行以下代码.

Create a simple Java source file and run (on your system) the following code.

package time;

import java.util.TimeZone;

public class TZDump
{
    public static void main(String[] args)
    {
        TimeZone mytz = TimeZone.getDefault();
        System.out.printf("The TimeZone for this machine: %s%n", mytz);
        for (String string : TimeZone.getAvailableIDs(mytz.getRawOffset())) {
            System.out.println(string);
        }   
    }
}

因此对于我的机器,此报告...

So for my machine, this reports ...

SystemV/MST7MDT
US/Arizona
US/Mountain

我很幸运,因为这个列表很小,对我来说,一个好处是没有遵守我的夏令时.就我而言,我将使用"US/Arizona".

I'm lucky, as this is list is small, and a bonus for me is that where I live Daylights Savings Time is not observed. In my case, I'll use "US/Arizona".

在您的情况下,您会看到一个较大的列表(只是因为您离欧洲如此之近). 选择以"Europe/"开头的条目(我想您的条目将为"Europe/London")

In your case, you'll see a larger list (just because you are so close to Europe). Choose an entry that starts with "Europe/" (I'm guessing yours will be "Europe/London")

现在在您的配置中使用该长格式的TimeZone标识符.

Now use that long form TimeZone identifier in your configuration.

<Set name="LogTimeZone">Europe/London</Set>

这篇关于让码头以正确的时区记录日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆