PERF: Cache `hostname` in `DiscourseLogstashLogger` (#27442)
Logging events happen all the time. No need for us to keep running code to fetch the hostname when it doesn't change between deploys.
This commit is contained in:
parent
30f369fffe
commit
be4f1e3350
|
@ -3,21 +3,22 @@
|
||||||
require "logstash-logger"
|
require "logstash-logger"
|
||||||
|
|
||||||
class DiscourseLogstashLogger
|
class DiscourseLogstashLogger
|
||||||
def self.logger(uri:, type:)
|
def self.hostname
|
||||||
# See Discourse.os_hostname
|
@hostname ||=
|
||||||
hostname =
|
|
||||||
begin
|
begin
|
||||||
require "socket"
|
require "socket"
|
||||||
Socket.gethostname
|
Socket.gethostname
|
||||||
rescue => e
|
rescue => e
|
||||||
`hostname`.chomp
|
`hostname`.chomp
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.logger(uri:, type:)
|
||||||
LogStashLogger.new(
|
LogStashLogger.new(
|
||||||
uri: uri,
|
uri: uri,
|
||||||
sync: true,
|
sync: true,
|
||||||
customize_event: ->(event) do
|
customize_event: ->(event) do
|
||||||
event["hostname"] = hostname
|
event["hostname"] = self.hostname
|
||||||
event["severity_name"] = event["severity"]
|
event["severity_name"] = event["severity"]
|
||||||
event["severity"] = Object.const_get("Logger::Severity::#{event["severity"]}")
|
event["severity"] = Object.const_get("Logger::Severity::#{event["severity"]}")
|
||||||
event["type"] = type
|
event["type"] = type
|
||||||
|
|
Loading…
Reference in New Issue