mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:38:17 +08:00
28292d2759
Previously we had many places in the app that called `hostname` to get hostname of a server. This commit replaces the pattern in 2 ways 1. We cache the result in `Discourse.os_hostname` so it is only ever called once 2. We prefer to use Socket.gethostname which avoids making a shell command This improves performance as we are not spawning hostname processes throughout the app lifetime
20 lines
489 B
Ruby
20 lines
489 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'logstash-logger'
|
|
|
|
class DiscourseLogstashLogger
|
|
def self.logger(uri:, type:)
|
|
LogStashLogger.new(
|
|
uri: uri,
|
|
sync: true,
|
|
customize_event: ->(event) {
|
|
event['hostname'] = Discourse.os_hostname
|
|
event['severity_name'] = event['severity']
|
|
event['severity'] = Object.const_get("Logger::Severity::#{event['severity']}")
|
|
event['type'] = type
|
|
event['pid'] = Process.pid
|
|
},
|
|
)
|
|
end
|
|
end
|