0

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

nadavgam
  • 2,014
  • 5
  • 20
  • 48

1 Answers1

1

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
engineersmnky
  • 25,495
  • 2
  • 36
  • 52