Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby logger loses formatting

Tags:

logging

ruby

I have a ruby console application. When I check it in irb on my dev machine, it logs ok. But when I run it in VM ruby logger loses formatting, i.e. it logs only message, without date and severity. Now this is solved by setting formatting with Logger.formatter = proc { |severity, datetime, progname, msg| ...}. But I'm curious as to why that could happen? I googled and found rather old info that this could happen in Rails application. Is this a known issue? It took me some time to debug this.

like image 385
Art Shayderov Avatar asked Dec 09 '25 12:12

Art Shayderov


1 Answers

Are you requireing different gems in the different environments, or could it be IRB itself that sets the log format? What happens if you add require 'irb' to your application, does that also change the formatting?

The formatting is stored in a global variable, any gem can override it. I've been bitten by a similar issue when I required a gem that in turn required ActiveRecord, which set the log format.

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

like image 62
Theo Avatar answered Dec 11 '25 01:12

Theo