Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logging): PPT-1368 - logging to use placeos-log-backend #381

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class PlaceOS::Driver; end
require "action-controller"

# Application code
require "./logging"
require "./placeos-rest-api"
require "./logging"
require "./telemetry"

# Server required after application controllers
Expand Down
4 changes: 4 additions & 0 deletions src/constants.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module PlaceOS::Api
APP_NAME = "rest-api"
API_VERSION = "v2"

Log = ::Log.for(self)

# Calculate version, build time, commit at compile time
VERSION = {{ system(%(shards version "#{__DIR__}")).chomp.stringify.downcase }}
BUILD_TIME = {{ system("date -u").stringify }}
Expand Down Expand Up @@ -54,4 +56,6 @@ module PlaceOS::Api
"CHANGELOG is not generated for development builds"
{% end %}
end

class_getter? production : Bool = PROD
end
30 changes: 0 additions & 30 deletions src/placeos-rest-api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,4 @@ require "./placeos-rest-api/controllers/application"
require "./placeos-rest-api/controllers/*"

module PlaceOS::Api
Log = ::Log.for(self)

LOG_STDOUT = ActionController.default_backend
LOGSTASH_HOST = ENV["LOGSTASH_HOST"]?
LOGSTASH_PORT = ENV["LOGSTASH_PORT"]?

def self.log_backend
if !(logstash_host = LOGSTASH_HOST.presence).nil?
logstash_port = LOGSTASH_PORT.try(&.to_i?) || abort("LOGSTASH_PORT is either malformed or not present in environment")

# Logstash UDP Input
logstash = UDPSocket.new
logstash.connect logstash_host, logstash_port
logstash.sync = false

# debug at the broadcast backend level, however this will be filtered
# by the bindings
backend = ::Log::BroadcastBackend.new
backend.append(LOG_STDOUT, :trace)
backend.append(ActionController.default_backend(
io: logstash,
formatter: ActionController.json_formatter
), :trace)
backend
else
LOG_STDOUT
end
end

class_getter? production : Bool = PROD
end
Loading