mirror of
https://github.com/jbranchaud/til
synced 2026-01-21 16:08:03 +00:00
Add Check The Current Named Log Level as a Rails TIL
This commit is contained in:
@@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/).
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
|
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
|
||||||
|
|
||||||
_1731 TILs and counting..._
|
_1732 TILs and counting..._
|
||||||
|
|
||||||
See some of the other learning resources I work on:
|
See some of the other learning resources I work on:
|
||||||
|
|
||||||
@@ -1073,6 +1073,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
|||||||
- [Check If ActiveRecord Update Fails](rails/check-if-activerecord-update-fails.md)
|
- [Check If ActiveRecord Update Fails](rails/check-if-activerecord-update-fails.md)
|
||||||
- [Check If Any Records Have A Null Value](rails/check-if-any-records-have-a-null-value.md)
|
- [Check If Any Records Have A Null Value](rails/check-if-any-records-have-a-null-value.md)
|
||||||
- [Check Specific Attributes On ActiveRecord Array](rails/check-specific-attributes-on-activerecord-array.md)
|
- [Check Specific Attributes On ActiveRecord Array](rails/check-specific-attributes-on-activerecord-array.md)
|
||||||
|
- [Check The Current Named Log Level](rails/check-the-current-named-log-level.md)
|
||||||
- [Clean Up Memory Hungry Rails Console Processes](rails/clean-up-memory-hungry-rails-console-processes.md)
|
- [Clean Up Memory Hungry Rails Console Processes](rails/clean-up-memory-hungry-rails-console-processes.md)
|
||||||
- [Code Statistics For An Application](rails/code-statistics-for-an-application.md)
|
- [Code Statistics For An Application](rails/code-statistics-for-an-application.md)
|
||||||
- [Columns With Default Values Are Nil On Create](rails/columns-with-default-values-are-nil-on-create.md)
|
- [Columns With Default Values Are Nil On Create](rails/columns-with-default-values-are-nil-on-create.md)
|
||||||
|
|||||||
46
rails/check-the-current-named-log-level.md
Normal file
46
rails/check-the-current-named-log-level.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Check The Current Named Log Level
|
||||||
|
|
||||||
|
I'm connected to a `rails console` session for an active Rails app. I want to
|
||||||
|
check the current log level.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
> Rails.logger.level
|
||||||
|
=> 1
|
||||||
|
```
|
||||||
|
|
||||||
|
The `1` doesn't mean much to me at a glance. I can translate that to the
|
||||||
|
severity level using the `Logger::SEV_LABLE` constant.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
[44] pry(main)> Logger::SEV_LABEL[Rails.logger.level]
|
||||||
|
=> "INFO"
|
||||||
|
```
|
||||||
|
|
||||||
|
Ah yes, `INFO`, that makes sense as the default.
|
||||||
|
|
||||||
|
I can see all the severity levels by inspecting the constant itself.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
[45] pry(main)> Logger::SEV_LABEL
|
||||||
|
=> ["DEBUG", "INFO", "WARN", "ERROR", "FATAL", "ANY"]
|
||||||
|
```
|
||||||
|
|
||||||
|
As I convenience, I can set the label using the index, the string, or even a
|
||||||
|
symbol.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
> Rails.logger.level
|
||||||
|
=> 1
|
||||||
|
> Rails.logger.level = "WARN"
|
||||||
|
=> "WARN"
|
||||||
|
> Rails.logger.level
|
||||||
|
=> 2
|
||||||
|
> Rails.logger.level = :debug
|
||||||
|
=> :debug
|
||||||
|
> Rails.logger.level
|
||||||
|
=> 0
|
||||||
|
```
|
||||||
|
|
||||||
|
See the [Debugging Rails Applications
|
||||||
|
guide](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels)
|
||||||
|
for more details.
|
||||||
Reference in New Issue
Block a user