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. ...@@ -191,7 +191,7 @@ Here are some examples of how messages would be handled by both the loggers.
FancyMultiLogger.info("Information") FancyMultiLogger.info("Information")
# UnstructuredLogger # UnstructuredLogger
I, [2020-01-13T12:02:41.566219 #6652] INFO -- : Information I, [2020-01-13T18:48:49.201Z #5647] INFO -- : Information
# StructuredLogger # StructuredLogger
{:severity=>"INFO", :time=>"2020-01-13T11:02:41.559Z", :correlation_id=>"b1701f7ecc4be4bcd4c2d123b214e65a", :message=>"Information"} {: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 ...@@ -203,7 +203,7 @@ I, [2020-01-13T12:02:41.566219 #6652] INFO -- : Information
FancyMultiLogger.info({:message=>"This is my message", :project_id=>123}) FancyMultiLogger.info({:message=>"This is my message", :project_id=>123})
# UnstructuredLogger # 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 # StructuredLogger
{:severity=>"INFO", :time=>"2020-01-13T11:06:09.851Z", :correlation_id=>"d7e0886f096db9a8526a4f89da0e45f6", :message=>"This is my message", :project_id=>123} {: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 ...@@ -7,7 +7,7 @@ module Gitlab
end end
def format_message(severity, timestamp, progname, msg) def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_s(:long)}: #{msg}\n" "#{timestamp.utc.iso8601(3)}: #{msg}\n"
end end
end end
end end
...@@ -15,4 +15,11 @@ describe Gitlab::AppTextLogger do ...@@ -15,4 +15,11 @@ describe Gitlab::AppTextLogger do
it 'logs a string unchanged' do it 'logs a string unchanged' do
expect(subject.format_message('INFO', Time.now, nil, string_message)).to include(string_message) expect(subject.format_message('INFO', Time.now, nil, string_message)).to include(string_message)
end 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 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