Skip to content

Commit 20b1a83

Browse files
Merge pull request #25 from browserstack/PP-795-CG-logs-improve
Introducing thread level variables instead of global
2 parents 34e3278 + 099c92f commit 20b1a83

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/chitragupta.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
module Chitragupta
1111
extend self
12-
attr_accessor :payload
1312

1413
# The gem can be used by adding the following in any of the rails initializations: application.rb / environment.rb
1514
# Chitragupta::setup_application_logger(RailsApplicationModule, current_user_function)
@@ -26,7 +25,7 @@ def setup_application_logger(app, current_user_caller=nil)
2625

2726
ActiveSupport::Notifications.subscribe "start_processing.action_controller" do |_name, _started, _finished, _unique_id, data|
2827
data[:params] = Chitragupta::Util::trim_long_string(data[:params].to_json.to_s, Chitragupta::Constants::FIELD_LENGTH_LIMITS[:params]) rescue nil
29-
Chitragupta.payload = data
28+
self.payload = data
3029
end
3130

3231
ActiveSupport::Notifications.subscribe "halted_callback.action_controller" do |_name, _started, _finished, _unique_id, data|
@@ -50,6 +49,14 @@ def get_unique_log_id
5049
return SecureRandom.uuid
5150
end
5251

52+
def payload
53+
Thread.current[:chitragupta_payload]
54+
end
55+
56+
def payload=(val)
57+
Thread.current[:chitragupta_payload] = val
58+
end
59+
5360
private
5461
def configure_app(app)
5562
app::Application.configure do

0 commit comments

Comments
 (0)