Skip to content

Commit bab9d24

Browse files
committed
log instead of logger
1 parent c69d2a7 commit bab9d24

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

lib/hooks/app/api.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ module App
1111
# Factory for creating configured Grape API classes
1212
class API
1313
# Create a new configured API class
14-
def self.create(config:, endpoints:, logger:, signal_handler:)
14+
def self.create(config:, endpoints:, log:, signal_handler:)
1515
# Store startup time for uptime calculation
1616
start_time = Time.now
1717

1818
# Capture values in local variables for closure
1919
captured_config = config
2020
captured_endpoints = endpoints
21-
captured_logger = logger
21+
captured_logger = log
2222
_captured_signal_handler = signal_handler
2323
captured_start_time = start_time
2424

@@ -175,7 +175,7 @@ def determine_error_code(exception)
175175

176176
# Use captured values
177177
config = captured_config
178-
logger = captured_logger
178+
log = captured_logger
179179

180180
# Set request context for logging
181181
request_context = {
@@ -194,9 +194,7 @@ def determine_error_code(exception)
194194
raw_body = request.body.read
195195

196196
# Verify/validate request if configured
197-
logger.info "validating request (id: #{request_id}, handler: #{handler_class_name})"
198-
logger.debug "raw body: #{raw_body.inspect}"
199-
logger.debug "headers: #{headers.inspect}"
197+
log.info "validating request (id: #{request_id}, handler: #{handler_class_name})"
200198
validate_request(raw_body, headers, endpoint_config) if endpoint_config[:request_validator]
201199

202200
# Parse payload
@@ -212,15 +210,15 @@ def determine_error_code(exception)
212210
config: endpoint_config
213211
)
214212

215-
logger.info "request processed successfully (id: #{request_id}, handler: #{handler_class_name})"
213+
log.info "request processed successfully (id: #{request_id}, handler: #{handler_class_name})"
216214

217215
# Return response as JSON string when using txt format
218216
status 200 # Explicitly set status to 200
219217
content_type "application/json"
220218
(response || { status: "ok" }).to_json
221219

222220
rescue => e
223-
logger.error "request failed: #{e.message} (id: #{request_id}, handler: #{handler_class_name})"
221+
log.error "request failed: #{e.message} (id: #{request_id}, handler: #{handler_class_name})"
224222

225223
# Return error response
226224
error_response = {
@@ -251,7 +249,7 @@ def determine_error_code(exception)
251249

252250
# Use captured values
253251
config = captured_config
254-
logger = captured_logger
252+
log = captured_logger
255253

256254
# Set request context for logging
257255
request_context = {
@@ -282,15 +280,15 @@ def determine_error_code(exception)
282280
config: {}
283281
)
284282

285-
logger.info "request processed successfully with default handler (id: #{request_id})"
283+
log.info "request processed successfully with default handler (id: #{request_id})"
286284

287285
# Return response as JSON string when using txt format
288286
status 200
289287
content_type "application/json"
290288
(response || { status: "ok" }).to_json
291289

292290
rescue StandardError => e
293-
logger.error "request failed: #{e.message} (id: #{request_id})"
291+
log.error "request failed: #{e.message} (id: #{request_id})"
294292

295293
# Return error response
296294
error_response = {

lib/hooks/core/builder.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class Builder
1515
# @param config [String, Hash] Path to config file or config hash
1616
# @param log [Logger] Custom logger instance
1717
def initialize(config: nil, log: nil)
18+
@log = log
1819
@config_input = config
19-
@custom_logger = log
2020
end
2121

2222
# Build and return Rack-compatible application
@@ -26,29 +26,31 @@ def build
2626
# Load and validate configuration
2727
config = load_and_validate_config
2828

29-
# Create logger
30-
logger = LoggerFactory.create(
31-
log_level: config[:log_level],
32-
custom_logger: @custom_logger
33-
)
29+
# Create logger unless a custom logger is provided
30+
if @log.nil?
31+
@log = LoggerFactory.create(
32+
log_level: config[:log_level],
33+
custom_logger: @custom_logger
34+
)
35+
end
3436

3537
# Setup signal handler for graceful shutdown
36-
signal_handler = SignalHandler.new(logger)
38+
signal_handler = SignalHandler.new(@log)
3739

3840
# Load endpoints
3941
endpoints = load_endpoints(config)
4042

4143
# Log startup
42-
logger.info "starting hooks server v#{Hooks::VERSION}"
43-
logger.info "config: #{endpoints.size} endpoints loaded"
44-
logger.info "environment: #{config[:environment]}"
45-
logger.info "available endpoints: #{endpoints.map { |e| e[:path] }.join(', ')}"
44+
@log.info "starting hooks server v#{Hooks::VERSION}"
45+
@log.info "config: #{endpoints.size} endpoints loaded"
46+
@log.info "environment: #{config[:environment]}"
47+
@log.info "available endpoints: #{endpoints.map { |e| e[:path] }.join(', ')}"
4648

4749
# Build and return Grape API class
4850
Hooks::App::API.create(
4951
config: config,
5052
endpoints: endpoints,
51-
logger: logger,
53+
log: @log,
5254
signal_handler: signal_handler
5355
)
5456
end

0 commit comments

Comments
 (0)