Tag: Rails/ログ出力
#サイズで分割(10MBごと) config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024) config.logger = Logger.new(config.paths["log"].first, 5, 10.megabytes) #日別 config.logger = Logger.new("log/production.log", 'daily')
ちなみにconfig.paths["log"].firstは"log/production.rb"が格納されている。pathsは複数のパスを管理することができるPathクラスのオブジェクトだがここでは1つの要素しか格納されていない模様。
Started GET "/books" for 127.0.0.1 at 2019-01-23 17:50:05 +0900 (0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC Processing by BooksController#index as HTML Rendering books/index.html.erb within layouts/application Book Load (0.2ms) SELECT "books".* FROM "books" Rendered books/index.html.erb within layouts/application (3.8ms) Completed 200 OK in 291ms (Views: 276.9ms | ActiveRecord: 0.5ms)
I, [2019-01-23T17:52:25.168643 #90293] INFO -- : Started GET "/books" for 127.0.0.1 at 2019-01-23 17:52:25 +0900 I, [2019-01-23T17:52:25.176907 #90293] INFO -- : Processing by BooksController#index as HTML I, [2019-01-23T17:52:25.194435 #90293] INFO -- : Rendering books/index.html.erb within layouts/application D, [2019-01-23T17:52:25.197667 #90293] DEBUG -- : Book Load (0.5ms) SELECT "books".* FROM "books" I, [2019-01-23T17:52:25.199449 #90293] INFO -- : Rendered books/index.html.erb within layouts/application (4.8ms) I, [2019-01-23T17:52:25.498990 #90293] INFO -- : Completed 200 OK in 322ms (Views: 311.0ms | ActiveRecord: 1.3ms)
config.logger.formatter = MyFormatter.new
class LoggerFormatWithTime def call(severity, timestamp, progname, msg) "[#{timestamp.strftime("%Y/%m/%d %H:%M:%S" )}] [#{severity}] : #{String === msg ? msg : msg.inspect}\n" end end config.logger = Logger.new(config.paths["log"].first, 5, 10 * 1024 * 1024) # config.log_formatter = LoggerFormatWithTime.new # これは無意味 config.logger.formatter = LoggerFormatWithTime.new #これが正解