Skip to content

Commit 82a60ff

Browse files
committed
[logging] few more tweaks for disabling logging
- tests need to read the right file - -1 is an accepted value - updates to the comment (=documentation) in the config file AO-10683
1 parent 1334eea commit 82a60ff

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

lib/appoptics_apm/config.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ def self.load_config_file
7171
# Oboe will override vars passed in if it finds an environment variable
7272
# :debug_level and :verbose need special consideration, because they are used in Ruby
7373
def self.check_env_vars
74-
unless (0..6).include?(AppOpticsAPM::Config[:debug_level])
75-
AppOpticsAPM::Config[:debug_level] = nil
74+
unless (-1..6).include?(AppOpticsAPM::Config[:debug_level])
75+
AppOpticsAPM::Config[:debug_level] = 3
7676
end
7777

78-
# let's use the same debug level for ruby as well,
79-
debug_level = ENV['APPOPTICS_DEBUG_LEVEL'].to_i || AppOpticsAPM::Config[:debug_level] || 3
78+
# let's find and use the equivalent debug level for ruby
79+
debug_level = ENV['APPOPTICS_DEBUG_LEVEL'] ? ENV['APPOPTICS_DEBUG_LEVEL'].to_i : AppOpticsAPM::Config[:debug_level]
8080
if debug_level < 0
8181
# there should be no logging if APPOPTICS_DEBUG_LEVEL == -1
8282
# In Ruby level 5 is UNKNOWN and it can log, but level 6 is quiet

lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727

2828
#
2929
# Set APPOPTICS_DEBUG_LEVEL
30-
# This Setting will be overridden if APPOPTICS_DEBUG_LEVEL is set as an environment variable
30+
# This setting will be overridden if APPOPTICS_DEBUG_LEVEL is set as an environment variable.
3131
#
3232
# It sets the log level and takes the following values:
33-
## 0 fatal, 1 error, 2 warning, 3 info (the default), 4 debug low, 5 debug medium, 6 debug high.
34-
#
33+
# -1 disabled, 0 fatal, 1 error, 2 warning, 3 info (the default), 4 debug low, 5 debug medium, 6 debug high.
34+
# Values < -1 or > 6 will set the log level to the default (info).
3535
#
3636
AppOpticsAPM::Config[:debug_level] = 3
3737
#
3838
# :debug_level will be used in the c-extension of the gem and also mapped to the
39-
# Ruby logger as FATAL, ERROR, WARN, INFO, or DEBUG
40-
# The Ruby logger can afterwards be changed to a different level as follows:
39+
# Ruby logger as DISABLED, FATAL, ERROR, WARN, INFO, or DEBUG
40+
# The Ruby logger can afterwards be changed to a different level, e.g:
4141
# AppOpticsAPM.logger.level = Logger::INFO
4242

4343
#

test/support/config_test.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ConfigTest
5656
f.puts "AppOpticsAPM::Config[:debug_level] = 6"
5757
f.puts "AppOpticsAPM::Config[:verbose] = true"
5858
end
59-
59+
ENV['APPOPTICS_APM_CONFIG_RUBY'] = @@default_config_path
6060
AppOpticsAPM::Config.load_config_file
6161

6262
ENV['APPOPTICS_SERVICE_KEY'].must_be_nil
@@ -86,7 +86,7 @@ class ConfigTest
8686
f.puts "AppOpticsAPM::Config[:debug_level] = 6"
8787
f.puts "AppOpticsAPM::Config[:verbose] = false"
8888
end
89-
89+
ENV['APPOPTICS_APM_CONFIG_RUBY'] = @@default_config_path
9090
AppOpticsAPM::Config.load_config_file
9191

9292
ENV['APPOPTICS_SERVICE_KEY'].must_equal '22222222-2222-2222-2222-222222222222:the_service_name'
@@ -101,19 +101,31 @@ class ConfigTest
101101
File.open(@@default_config_path, 'w') do |f|
102102
f.puts "AppOpticsAPM::Config[:debug_level] = 7"
103103
end
104-
104+
ENV['APPOPTICS_APM_CONFIG_RUBY'] = @@default_config_path
105105
AppOpticsAPM::Config.load_config_file
106106

107107
ENV['APPOPTICS_DEBUG_LEVEL'].must_be_nil
108-
AppOpticsAPM::Config[:debug_level].must_be_nil
108+
AppOpticsAPM::Config[:debug_level].must_equal 3
109109
AppOpticsAPM.logger.level.must_equal Logger::INFO
110110
end
111111

112+
it "should accept -1 (disable logging)" do
113+
File.open(@@default_config_path, 'w') do |f|
114+
f.puts "AppOpticsAPM::Config[:debug_level] = -1"
115+
end
116+
ENV['APPOPTICS_APM_CONFIG_RUBY'] = @@default_config_path
117+
AppOpticsAPM::Config.load_config_file
118+
119+
ENV['APPOPTICS_DEBUG_LEVEL'].must_be_nil
120+
AppOpticsAPM::Config[:debug_level].must_equal -1
121+
AppOpticsAPM.logger.level.must_equal 6
122+
end
123+
112124
it "should accept 'true'/'TRUE'/'True'/... as true for VERBOSE" do
113125
File.open(@@default_config_path, 'w') do |f|
114126
f.puts "AppOpticsAPM::Config[:verbose] = false"
115127
end
116-
128+
ENV['APPOPTICS_APM_CONFIG_RUBY'] = @@default_config_path
117129
ENV['APPOPTICS_GEM_VERBOSE'] = 'FALSE'
118130
AppOpticsAPM::Config.load_config_file
119131
AppOpticsAPM::Config[:verbose].wont_equal true

0 commit comments

Comments
 (0)