Is there a 'built in' method to get log level as a string and not as an integer in Ruby On Rails?

323 views Asked by At

I want to print the log level of our Rails web app. I get the log level as an integer when I run Rails.logger.level

My question - is there a built-in method to get the log level as a String("DEBUG","INFO" etc)

I can write a code to translate manually( if level == 0 puts "DEBUG") but it seems to me not to be a clean code solution

1

There are 1 answers

0
engineersmnky On

Rails Logger is just a fancy ruby Logger

Knowing this you could use:

Rails.logger.class::SEV_LABEL[Rails.logger.level] 
# or 
Rails.logger.send(:format_severity,Rails.logger.level)

but the real question is why?

There are more readable and idiomatic alternatives for your suggested code e.g.

if Rails.logger.debug?
# do something
else 
# don't 
end