@@ -4,7 +4,32 @@ class Engine < ::Rails::Engine
44
55 if Rails . version > '3.1'
66 initializer 'Stackify set up of logger' , group : :all do
7+ if Gem ::Version . new ( Rails ::VERSION ::STRING ) >= Gem ::Version . new ( '4.0' )
8+ # check if the client app is using the ActiveSupport::Logger
9+ is_activesupport_logger = ::Rails . logger . is_a? ( ActiveSupport ::Logger )
10+ elsif Gem ::Version . new ( Rails ::VERSION ::STRING ) >= Gem ::Version . new ( '3.0' )
11+ Stackify ::Utils . check_buffered_logger
12+ end
13+
14+ # Check if the log output is STDOUT
15+ Stackify ::Utils . check_log_output
16+
17+ # Proxy the client Rails logger and write logs to its default log_path.
18+ # At the same time, we send the log messages to the LoggerClient.
719 ::Rails . logger = ::Stackify ::LoggerProxy . new ::Rails . logger
20+
21+ if Gem ::Version . new ( Rails ::VERSION ::STRING ) >= Gem ::Version . new ( '6.0' )
22+ set_console_logs ::Rails . logger
23+ elsif Gem ::Version . new ( Rails ::VERSION ::STRING ) >= Gem ::Version . new ( '4.0' )
24+ if is_activesupport_logger && Stackify . configuration . stdout_output
25+ set_console_logs ::Rails . logger
26+ end
27+ # Another checking if the client app is using the default logger and not STDOUT
28+ if Stackify . configuration . stdout_output == false
29+ set_console_logs ::Rails . logger
30+ end
31+ end
32+
833 Stackify . run
934 end
1035
@@ -14,6 +39,16 @@ class Engine < ::Rails::Engine
1439 end
1540 end
1641
42+ def set_console_logs logger
43+ # Handle the stdout logs from Action Controller
44+ ActionController ::Base . logger = logger
45+
46+ # Handle the stdout logs from Action View
47+ ActionView ::Base . logger = logger
48+
49+ # Handle the stdout logs from Active Record
50+ ActiveRecord ::Base . logger = logger
51+ end
1752 end
1853
1954 end
0 commit comments