Commit 213f3c1f authored by Aakriti Gupta's avatar Aakriti Gupta Committed by Peter Leitzen

Use standard timestamp format for application logs

parent c6b6d03d
---
title: 'Use IS08601.3 format for app level logging of timestamps'
merge_request: 22793
author:
type: other
......@@ -191,7 +191,7 @@ Here are some examples of how messages would be handled by both the loggers.
FancyMultiLogger.info("Information")
# UnstructuredLogger
I, [2020-01-13T12:02:41.566219 #6652] INFO -- : Information
I, [2020-01-13T18:48:49.201Z #5647] INFO -- : Information
# StructuredLogger
{:severity=>"INFO", :time=>"2020-01-13T11:02:41.559Z", :correlation_id=>"b1701f7ecc4be4bcd4c2d123b214e65a", :message=>"Information"}
......@@ -203,7 +203,7 @@ I, [2020-01-13T12:02:41.566219 #6652] INFO -- : Information
FancyMultiLogger.info({:message=>"This is my message", :project_id=>123})
# UnstructuredLogger
I, [2020-01-13T12:06:09.856766 #8049] INFO -- : {:message=>"This is my message", :project_id=>123}
I, [2020-01-13T19:01:17.091Z #11056] INFO -- : {"message"=>"Message", "project_id"=>"123"}
# StructuredLogger
{:severity=>"INFO", :time=>"2020-01-13T11:06:09.851Z", :correlation_id=>"d7e0886f096db9a8526a4f89da0e45f6", :message=>"This is my message", :project_id=>123}
......
......@@ -7,7 +7,7 @@ module Gitlab
end
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_s(:long)}: #{msg}\n"
"#{timestamp.utc.iso8601(3)}: #{msg}\n"
end
end
end
......@@ -15,4 +15,11 @@ describe Gitlab::AppTextLogger do
it 'logs a string unchanged' do
expect(subject.format_message('INFO', Time.now, nil, string_message)).to include(string_message)
end
it 'logs time in UTC with ISO8601.3 standard' do
Timecop.freeze do
expect(subject.format_message('INFO', Time.now, nil, string_message))
.to include(Time.now.utc.iso8601(3))
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