2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-13 22:50:26 -06:00
|
|
|
require "logstash-logger"
|
|
|
|
|
|
|
|
class DiscourseLogstashLogger
|
|
|
|
def self.logger(uri:, type:)
|
2020-02-18 05:37:39 -06:00
|
|
|
# See Discourse.os_hostname
|
|
|
|
hostname =
|
|
|
|
begin
|
|
|
|
require "socket"
|
|
|
|
Socket.gethostname
|
|
|
|
rescue => e
|
|
|
|
`hostname`.chomp
|
|
|
|
end
|
|
|
|
|
2017-11-13 22:50:26 -06:00
|
|
|
LogStashLogger.new(
|
|
|
|
uri: uri,
|
|
|
|
sync: true,
|
|
|
|
customize_event: ->(event) do
|
2020-02-18 05:37:39 -06:00
|
|
|
event["hostname"] = hostname
|
2017-11-13 22:50:26 -06:00
|
|
|
event["severity_name"] = event["severity"]
|
2017-11-16 18:54:53 -06:00
|
|
|
event["severity"] = Object.const_get("Logger::Severity::#{event["severity"]}")
|
2017-11-13 22:50:26 -06:00
|
|
|
event["type"] = type
|
2018-04-16 23:07:13 -05:00
|
|
|
event["pid"] = Process.pid
|
2017-11-13 22:50:26 -06:00
|
|
|
end,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|