Skip to content

Commit

Permalink
fix(logging): PPT-1368 - logging to use placeos-log-backend (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis authored May 13, 2024
1 parent f926a1c commit 30c1498
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ abstract class PlaceOS::Driver; end
class PlaceOS::Driver::Protocol; end

# Application code
require "./placeos-core"
require "./logging"
require "./constants"

require "./placeos-core"
require "./api/*"

# Require telemetry after application code
Expand Down
2 changes: 2 additions & 0 deletions src/constants.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module PlaceOS::Core

REDIS_URL = ENV["REDIS_URL"]? || "redis://localhost:6379"

Log = ::Log.for(self)

# seconds before a node is considered offline
# should not be divisible by 3
CLUSTER_NODE_TTL = (ENV["CLUSTER_NODE_TTL"]? || "20").to_i
Expand Down
1 change: 0 additions & 1 deletion src/logging.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require "./constants"

module PlaceOS::Core::Logging
::Log.progname = APP_NAME

# Configure logging
log_backend = PlaceOS::LogBackend.log_backend
log_level = Core.production? ? ::Log::Severity::Info : ::Log::Severity::Debug
Expand Down
28 changes: 0 additions & 28 deletions src/placeos-core.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,10 @@ require "./placeos-core/*"
require "./constants"

module PlaceOS::Core
Log = ::Log.for(self)
LOG_STDOUT = ActionController.default_backend
LOGSTASH_HOST = ENV["LOGSTASH_HOST"]?
LOGSTASH_PORT = ENV["LOGSTASH_PORT"]?

# Minimize the number of connections being made to redis
REDIS_LOCK = Driver::RedisStorage.redis_lock
REDIS_CLIENT = Driver::RedisStorage.shared_redis_client

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

def self.start_managers
resource_manager = ResourceManager.instance
module_manager = ModuleManager.instance
Expand Down

0 comments on commit 30c1498

Please sign in to comment.