Closed TangMonk closed 9 years ago
Thanks for creating the issue :) Can you please pass me your grape/rails versions?
thanks for your reply, my version:
gem 'rails', '4.1.10'
gem 'grape', '0.11.0'
should it be like the following?
logger = Logger.new( GrapeLogging::MultiIO.new([STDOUT, File.open('log/api.log', 'a')] ) )
logger.formatter = GrapeLogging::Formatters::Default.new
use GrapeLogging::Middleware::RequestLogger, { logger: logger }
@thimios I think you are on the right path :) The array is not required but I've overlooked the 'a'
modifier - it's outside the File.open
function - thanks for noticing!
So the original line should look like this:
logger Logger.new(GrapeLogging::MultiIO.new(STDOUT, File.open("#{Rails.root}/log/development.log", 'a')))
Fixed with commit 43f945badc09a2289c955300d96bf6fcfe79f359
You still have one parenthesis more than needed.
Dont you also need an assignment ( = ) ? Like this:
logger.formatter = GrapeLogging::Formatters::Default.new logger = Logger.new GrapeLogging::MultiIO.new(STDOUT, File.open('path/to/your/logfile.log', 'a')) use GrapeLogging::Middleware::RequestLogger, { logger: logger }
You are correct about the parenthesis, changed that. But the assignment is not needed, check the grape doc: https://github.com/intridea/grape#logging
great thanks.
I try it like this:
logger Logger.new GrapeLogging::MultiIO.new( STDOUT, File.open('log/api.log', 'a'))
use GrapeLogging::Middleware::RequestLogger, { logger: logger }
the file is created, but it stays empty. Any ideas?
Yes, that's ruby buffering writes to the file. You need to set sync = true
on the log file to see logs immediately http://stackoverflow.com/questions/8948933/what-does-file-sync-true-do
so finally I have this and it works great:
logfile = File.open('log/api.log', 'a')
logfile.sync = true
logger Logger.new GrapeLogging::MultiIO.new(STDOUT, logfile)
logger.formatter = GrapeLogging::Formatters::Default.new
use GrapeLogging::Middleware::RequestLogger, { logger: logger }
what do you mean?
I am sorry, the last line of my previous comment did not make much sense, so I removed it.
But throw me