Skip to content

Commit a32f503

Browse files
authored
Merge pull request #447 from cncf/hotfix/400_logger_env_var
allow underscore in logger level set env var name
2 parents e05eff1 + b0b6867 commit a32f503

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

spec/utils/utils_spec.cr

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,21 @@ describe "Utils" do
267267
it "'logger' command line logger level setting works", tags: ["logger", "happy-path"] do
268268
# Note: implicitly tests the override of config.yml if it exist in repo root
269269
response_s = `./cnf-conformance -l debug test`
270+
LOGGING.info response_s
271+
$?.success?.should be_true
272+
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should_not be_nil
273+
end
274+
275+
it "'logger' LOGLEVEL NO underscore environment variable level setting works", tags: ["logger", "happy-path"] do
276+
# Note: implicitly tests the override of config.yml if it exist in repo root
277+
response_s = `unset LOG_LEVEL; LOGLEVEL=DEBUG ./cnf-conformance test`
270278
$?.success?.should be_true
271279
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should_not be_nil
272280
end
273281

274-
it "'logger' environment variable level setting works", tags: ["logger", "happy-path"] do
282+
it "'logger' LOG_LEVEL WITH underscore environment variable level setting works", tags: ["logger", "happy-path"] do
275283
# Note: implicitly tests the override of config.yml if it exist in repo root
276-
response_s = `LOGLEVEL=DEBUG ./cnf-conformance test`
284+
response_s = `LOG_LEVEL=DEBUG ./cnf-conformance test`
277285
$?.success?.should be_true
278286
(/DEBUG -- cnf-conformance: debug test/ =~ response_s).should_not be_nil
279287
end
@@ -289,7 +297,7 @@ describe "Utils" do
289297

290298
it "'logger' defaults to error when level set is missplled", tags: ["logger"] do
291299
# Note: implicitly tests the override of config.yml if it exist in repo root
292-
response_s = `LOGLEVEL=DEGUB ./cnf-conformance test`
300+
response_s = `unset LOG_LEVEL; LOGLEVEL=DEGUB ./cnf-conformance test`
293301
$?.success?.should be_true
294302
(/ERROR -- cnf-conformance: Invalid logging level set. defaulting to ERROR/ =~ response_s).should_not be_nil
295303
end

src/tasks/utils/utils.cr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ end
5858

5959
# this first line necessary to make sure our custom formatter
6060
# is used in the default error log line also
61-
Log.setup(Log::Severity::Error, Log::IOBackend.new(formatter: log_formatter))
62-
Log.setup(loglevel, Log::IOBackend.new(formatter: log_formatter))
61+
Log.setup(Log::Severity::Error, Log::IOBackend.new(formatter: log_formatter))
62+
Log.setup(loglevel, Log::IOBackend.new(formatter: log_formatter))
6363

6464

6565
def loglevel
@@ -84,6 +84,10 @@ def loglevel
8484
levelstr = ENV["LOGLEVEL"]
8585
end
8686

87+
if ENV.has_key?("LOG_LEVEL")
88+
levelstr = ENV["LOG_LEVEL"]
89+
end
90+
8791
# highest priority is last
8892
if !LogLevel.command_line_loglevel.empty?
8993
levelstr = LogLevel.command_line_loglevel

0 commit comments

Comments
 (0)