Working on major restructuring

This commit is contained in:
2025-12-20 15:30:24 -07:00
parent f4c5ba1f14
commit 645a47b98a
53 changed files with 226 additions and 1407 deletions
+18
View File
@@ -0,0 +1,18 @@
module GameServer
module Logging
module Context
def self.with(data)
old = Thread.current[:log_ctx]
Thread.current[:log_ctx] = data
yield
ensure
Thread.current[:log_ctx] = old
end
def self.current
ctx = Thread.current[:log_ctx]
ctx ? ctx.map { |k,v| "#{k}=#{v} " }.join : ""
end
end
end
end
+11
View File
@@ -0,0 +1,11 @@
require "time"
module GameServer
module Logging
class Formatter
def call(severity, time, _, msg)
"[#{time.utc.iso8601}] #{severity} #{Context.current}#{msg}\n"
end
end
end
end
+19
View File
@@ -0,0 +1,19 @@
require "logger"
module GameServer
module Logging
def self.setup
FileUtils.mkdir_p("log")
file = File.open("log/development.log", "a")
file.sync = true
@logger = Logger.new(file)
@logger.level = Logger::DEBUG
@logger.formatter = Formatter.new
end
def self.logger
@logger
end
end
end