Ruby logger plays formatting

I have a console console application. When I test it on irb on my dev machine, it writes in order. But when I run it in VM ruby ​​logger loses formatting, that is, it only logs a message without date and severity. Now this is solved by setting the formatting with Logger.formatter = proc { |severity, datetime, progname, msg| ...}. But I'm curious why this could happen? I googled and found pretty old information that this could happen in a Rails application. Is this a known issue? It took me a while to debug this.

+3
source share
2 answers

Do you use requiredifferent gems in different environments, or can it be IRB itself, which sets the format of the magazine? What happens if you add require 'irb'to your application, it will also change the formatting?

Formatting is stored in a global variable, any gem can override it. I was bitten by a similar problem when I required gem, which in turn is required ActiveRecord, which sets the log format.

It just shows how bad it is to use global variables for configuration, which is too common in Ruby gems.

+2
source

FYI Rails 3, , , . , .

, Rails 3 , :

log = Logger.new('file.log')
log.formatter = proc { |severity, datetime, progname, msg| ...}
+1

Source: https://habr.com/ru/post/1791672/


All Articles