-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We’ve implemented log shipping at the platform level and this custom code to send our logs to Logstash is no longer required.
- Loading branch information
1 parent
b5dcf87
commit 0fe71e8
Showing
7 changed files
with
20 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,10 @@ | ||
class LogStashFormatter < SemanticLogger::Formatters::Raw | ||
def call(log, logger) | ||
super(log, logger) | ||
return unless defined?(SemanticLogger) | ||
|
||
format_exception | ||
format_stacktrace | ||
|
||
hash.to_json | ||
end | ||
|
||
def format_exception | ||
exception_message = hash.dig(:exception, :message) | ||
return if exception_message.blank? | ||
|
||
hash[:message] = "Exception occured: #{exception_message}" | ||
end | ||
|
||
def format_stacktrace | ||
stack_trace = hash.dig(:exception, :stack_trace) | ||
return if stack_trace.blank? | ||
|
||
hash[:stacktrace] = stack_trace.first(3) | ||
hash[:exception].delete(:stack_trace) | ||
end | ||
Rails.application.configure do | ||
config.semantic_logger.application = "" # This is added by logstash from its tags | ||
config.log_tags = [:request_id] # Prepend all log lines with the following tags | ||
end | ||
|
||
if ENV["LOGSTASH_HOST"] && ENV["LOGSTASH_PORT"] | ||
warn("logstash configured, sending logs there") | ||
|
||
# For some reason logstash / elasticsearch drops events where the payload | ||
# is a hash. These are more conveniently accessed at the top level of the | ||
# event, anyway, so we move it there. | ||
customize_event = ->(event) do | ||
if event["payload"].present? | ||
event.append(event["payload"]) | ||
event["payload"] = nil | ||
end | ||
end | ||
|
||
logger = | ||
LogStashLogger.new( | ||
{ | ||
host: ENV["LOGSTASH_HOST"], | ||
port: ENV["LOGSTASH_PORT"], | ||
ssl_enable: true, | ||
type: :tcp | ||
}.merge(customize_event:) | ||
) | ||
SemanticLogger.add_appender(logger:, level: :info, formatter: LogStashFormatter.new) | ||
end | ||
SemanticLogger.add_appender(io: $stdout, level: Rails.application.config.log_level, | ||
formatter: Rails.application.config.log_format) | ||
Rails.application.config.logger.info('Application logging to STDOUT') |
This file was deleted.
Oops, something went wrong.