Commit 428709d8 authored by Stan Hu's avatar Stan Hu

Merge branch 'ag-update-timestamps-unicorn' into 'master'

Standardize timestamps in Unicorn logs

See merge request gitlab-org/gitlab!24612
parents ed8abf6a 17c74e91
......@@ -82,6 +82,7 @@ preload_app true
check_client_connection false
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|
# Signal application hooks that we're about to restart
......@@ -137,3 +138,7 @@ after_fork do |server, worker|
# addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
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
check_client_connection false
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|
# Signal application hooks that we're about to restart
......@@ -70,3 +71,7 @@ after_fork do |server, worker|
# addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
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