Commit 17c74e91 authored by Aakriti Gupta's avatar Aakriti Gupta Committed by Stan Hu

Format Unicorn log timestamps

- to be in UTC
- and to be in ISO8601 format with seconds upto
3 fractional digits
parent 218e2fda
...@@ -82,6 +82,7 @@ preload_app true ...@@ -82,6 +82,7 @@ preload_app true
check_client_connection false check_client_connection false
require_relative "/home/git/gitlab/lib/gitlab/cluster/lifecycle_events" require_relative "/home/git/gitlab/lib/gitlab/cluster/lifecycle_events"
require_relative "/home/git/gitlab/lib/gitlab/log_timestamp_formatter.rb"
before_exec do |server| before_exec do |server|
# Signal application hooks that we're about to restart # Signal application hooks that we're about to restart
...@@ -137,3 +138,7 @@ after_fork do |server, worker| ...@@ -137,3 +138,7 @@ after_fork do |server, worker|
# addr = "127.0.0.1:#{9293 + worker.nr}" # addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true) # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
end end
# Configure the default logger to use a custom formatter that formats the
# timestamps to be in UTC and in ISO8601.3 format
Configurator::DEFAULTS[:logger].formatter = Gitlab::LogTimestampFormatter.new
...@@ -15,6 +15,7 @@ preload_app true ...@@ -15,6 +15,7 @@ preload_app true
check_client_connection false check_client_connection false
require_relative "/home/git/gitlab/lib/gitlab/cluster/lifecycle_events" require_relative "/home/git/gitlab/lib/gitlab/cluster/lifecycle_events"
require_relative "/home/git/gitlab/lib/gitlab/log_timestamp_formatter.rb"
before_exec do |server| before_exec do |server|
# Signal application hooks that we're about to restart # Signal application hooks that we're about to restart
...@@ -70,3 +71,7 @@ after_fork do |server, worker| ...@@ -70,3 +71,7 @@ after_fork do |server, worker|
# addr = "127.0.0.1:#{9293 + worker.nr}" # addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true) # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
end end
# Configure the default logger to use a custom formatter that formats the
# timestamps to be in UTC and in ISO8601.3 format
Configurator::DEFAULTS[:logger].formatter = Gitlab::LogTimestampFormatter.new
# frozen_string_literal: true
module Gitlab
class LogTimestampFormatter < Logger::Formatter
FORMAT = "%s, [%s #%d] %5s -- %s: %s\n"
def call(severity, timestamp, program_name, message)
FORMAT % [severity[0..0], timestamp.utc.iso8601(3), $$, severity, program_name, msg2str(message)]
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::LogTimestampFormatter do
subject { described_class.new }
let(:formatted_timestamp) { Time.now.utc.iso8601(3) }
it 'logs the timestamp in UTC and ISO8601.3 format' do
Timecop.freeze(Time.now) do
expect(subject.call('', Time.now, '', '')).to include formatted_timestamp
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment