Skip to content

Commit 044472b

Browse files
committed
Add logger accessor to Lifecycle and implement RequestMethodLogger example
1 parent 1b25383 commit 044472b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/hooks/plugins/lifecycle.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ def on_error(exception, env)
3131
# Override in subclass for error handling logic
3232
end
3333

34+
# Short logger accessor for all subclasses
35+
# @return [Hooks::Log] Logger instance
36+
#
37+
# Provides a convenient way for lifecycle plugins to log messages without needing
38+
# to reference the full Hooks::Log namespace.
39+
#
40+
# @example Logging an error in an inherited class
41+
# log.error("oh no an error occured")
42+
def log
43+
Hooks::Log.instance
44+
end
45+
3446
# Global stats component accessor
3547
# @return [Hooks::Core::Stats] Stats instance for metrics reporting
3648
#

spec/acceptance/config/hooks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Sample configuration for Hooks webhook server
22
handler_plugin_dir: ./spec/acceptance/plugins/handlers
33
auth_plugin_dir: ./spec/acceptance/plugins/auth
4+
lifecycle_plugin_dir: ./spec/acceptance/plugins/lifecycle
45

56
log_level: debug
67

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
# This is mostly just an example lifecycle plugin that logs the request method as a demonstration
4+
class RequestMethodLogger < Hooks::Plugins::Lifecycle
5+
def on_request(env)
6+
log.debug("on_request called with method: #{env['REQUEST_METHOD']}")
7+
end
8+
end

0 commit comments

Comments
 (0)