From 0a2cb5093f7fbba370fd9b6caaf308139220b47b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 19 Apr 2011 00:28:08 +0000 Subject: $time_local and $time_utc are locale-independent This doesn't apply to people that use strftime()-formats, but that's a minority. --- lib/clogger.rb | 4 ++-- lib/clogger/pure.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/clogger.rb b/lib/clogger.rb index e368115..be1bdce 100644 --- a/lib/clogger.rb +++ b/lib/clogger.rb @@ -19,8 +19,6 @@ class Clogger # support nginx variables that are less customizable than our own ALIASES = { '$request_time' => '$request_time{3}', - '$time_local' => '$time_local{%d/%b/%Y:%H:%M:%S %z}', - '$time_utc' => '$time_utc{%d/%b/%Y:%H:%M:%S %z}', '$msec' => '$time{3}', '$usec' => '$time{6}', '$http_content_length' => '$content_length', @@ -37,6 +35,8 @@ class Clogger :pid => 6, # getpid() :request_uri => 7, :time_iso8601 => 8, + :time_local => 9, + :time_utc => 10, } private diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb index a56b982..63907ae 100644 --- a/lib/clogger/pure.rb +++ b/lib/clogger/pure.rb @@ -137,6 +137,18 @@ private $$.to_s when :time_iso8601 Time.now.iso8601 + when :time_local + t = Time.now + off = t.utc_offset + sign = off < 0 ? '-' : '+' + sprintf("%02d/%s/%d:%02d:%02d:%02d #{sign}%02d%02d", + t.mday, Time::RFC2822_MONTH_NAME[t.mon - 1], + t.year, t.hour, t.min, t.sec, *(off.abs / 60).divmod(60)) + when :time_utc + t = Time.now.utc + sprintf("%02d/%s/%d:%02d:%02d:%02d +0000", + t.mday, Time::RFC2822_MONTH_NAME[t.mon - 1], + t.year, t.hour, t.min, t.sec) else raise "EDOOFUS #{special_nr}" end -- cgit v1.2.3-24-ge0c7