読者です 読者をやめる 読者になる 読者になる

ActiveRecordのloggerがカラーコードを付加してきて見づらいんです!

active record
ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
activerecord (3.1.0)
activerecord-oracle_enhanced-adapter (1.4.2)

loggerをしこんでActiveRecordのログを見てみる。

require 'logger'
ActiveRecord::Base.logger = Logger.new(STDOUT)

するってーと

D, [2013-06-19T00:31:05.994668 #7272] DEBUG -- :   [1m[36memployees Columns (2.0ms)[0m  [1mSELECT column_name AS nam
e, data_type AS sql_type, data_default, nullable, virtual_column, hidden_column, DECODE(data_type, 'NUMBER', data_precis
ion, 'FLOAT', data_precision, 'VARCHAR2', DECODE(char_used, 'C', char_length, data_length), 'RAW', DECODE(char_used, 'C'
, char_length, data_length), 'CHAR', DECODE(char_used, 'C', char_length, data_length), NULL) AS limit, DECODE(data_type,
 'NUMBER', data_scale, NULL) AS scale FROM all_tab_cols WHERE owner = 'HR' AND table_name = 'EMPLOYEES' AND hidden_colum
n = 'NO' ORDER BY column_id[0m
D, [2013-06-19T00:31:06.018669 #7272] DEBUG -- :   [1m[35m (12.0ms)[0m  SELECT DECODE(table_name, UPPER(table_name),
LOWER(table_name), table_name) FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N'
D, [2013-06-19T00:31:06.021669 #7272] DEBUG -- :   [1m[36mPrimary Key (2.0ms)[0m  [1mSELECT cc.column_name FROM all_
constraints c, all_cons_columns cc WHERE c.owner = 'HR' AND c.table_name = 'EMPLOYEES' AND c.constraint_type = 'P' AND c
c.owner = c.owner AND cc.constraint_name = c.constraint_name[0m
D, [2013-06-19T00:31:06.025669 #7272] DEBUG -- :   [1m[35mPrimary Key (2.0ms)[0m  SELECT cc.column_name FROM all_cons
traints c, all_cons_columns cc WHERE c.owner = 'HR' AND c.table_name = 'EMPLOYEES' AND c.constraint_type = 'P' AND cc.ow
ner = c.owner AND cc.constraint_name = c.constraint_name
D, [2013-06-19T00:31:06.117675 #7272] DEBUG -- :   [1m[36mEmployee Load (91.0ms)[0m  [1mSELECT "EMPLOYEES".* FROM "E
MPLOYEES" WHERE "EMPLOYEES"."EMPLOYEE_ID" = :a1 AND ROWNUM <= 1[0m  [["employee_id", 100]]

oh...rspecか何かで見たことある感じになってるわ。。

ブログによっては

ActiveRecord::Base.colorize_loggin = false

でカラーコードをなくせると書いてあるけど私にはできなかった。

ActiveSupport::LogSubscriber.colorize_logging = false

こっちですね。Rails3からの仕様だそうで。

参考