I am using Rails logger to log information in my Rails 4 application.
I do not set config.logger=Logger.new(STDOUT) in my configuration and just keep the default option for logger.However, besides the log file under /log folder, the information is still printed to the console when the statement Rails.logger.info is used.
Why does this happen as I only want the log info to be inside the log file, not printed to console? Thanks
Thats how rails s behaves. It puts the logs in log/development.log as well as show at the command line. As thats more convenient for most cases.
Anyways if you do not want it you can run your server something like this:
rails s 1> /dev/null
This would redirect all that text to /dev/null
If you only wants to print the log in log/development.log and not in the console, then use below to start your rails server.
rails s > log/development.log
Related
I currently have this issue that when there's an error, the logs in my terminal aren't informative. The logs are only writing to the log files but my terminal output doesn't show anything. This was super confusing. How do I change this?
What is the Rails default behavior anyway when it comes to logging?
In Rails, by default, each log is created under Rails.root/log/ and the log file is named after the environment in which the application is running.
But if you want to change you can specify something like below in config/application.rb which would throw out logs on STDOUT.
config.logger = Logger.new(STDOUT)
See the Rails guides for more info.
What I usually found easy was to tail the log on console like $ tail -f log/development.log and force/see the output of log file on console.
I'm trying to run a Ruby application, which outputs information to the console. I'd like to make this output get saved to a text/log file.
Is this even possible? There must be a flag for ruby to do this right?
Use shell redirections:
ruby script.rb > out.txt
rails server > out.txt
On another note, you may also redirect $stdout, $stderr:
$stdout = File.new('/path/to/out.txt', 'w')
http://eddymulyono.livejournal.com/65791.html
When I use rails/server (WEBrick) I get constant debug info (queries, etc) from my rails app as console output. Is there a way to get this debug output with Pow?
Thanks
You can check the HTTP requests that Pow receives by running tail -f on the log file of your choice in the ~/Library/Logs/Pow directory. Check out the Pow manual section on Viewing Log Files
If you're looking for Rails specific logs, they'll be located in the log/ directory of your application. For instance, if you want to watch the development log for your application switch to the root director of the application and run:
tail -f log/development.log
There's also less which will give you a few more options, but isn't quite as simple to use.
less -R log/development.log
and then press ctrl-f to follow new output to the file. Pressing h will give you a more detailed help menu.
You can also use a helper gem like powder. I order to show application log just type powder applog
Do you see a log/development.log path in your application? You can typically use that to see what is taking place within Rails. There are also logs for testing and production as well and they might be present for your project depending on the mode that the application is running in.
To access these logs you should use the Terminal and cd to your application, you can then use a utility such as tail to see the logs. A variation of the tail command would also scroll the output when there is new content like the Rails logger normally does.
Use the pry-remote gem.
References:
https://github.com/Mon-Ouie/pry-remote
https://coderwall.com/p/sreazq
I'm trying to do easy logging
logger.error "ERROR!!!"
But nothing is displayed in any of the log files in the /log directory. I tried rescuing an exception, but there's no exception.
What might be the problem here?
Did you check that your production.log file has the proper rights? Try running sudo chmod 0666 on your production.log file, that might be the problem.
there might be a:
permission problem. run "sudo chmod 0666" on the file. rails does show this when the server is started though
rails uses a BufferedLogger. try a "logger.flush" Can configure it as well.
what does "logger.class" say? what logger are you using?
is the log file created? what is its permission and the permission for the log folder?
are you running the server on webrick (locally ?) or passenger etc?
eg. if you say "Rails.logger = Logger.new(STDOUT)" then the logs will go to stdout rather than a file. check that as well
Check output of Rails.logger. If it shows RailsStdoutLogging::StdoutLogger:0x00007fe3b5bc3540 means you are logging on shell. Change it to ActiveSupport::Logger by creating an initializer.
config/initializer/logger.rb
Rails.logger = ActiveSupport::Logger.new('log/production.log')
I had a similar problem trying to use logger.debug and RAILS_DEFAULT_LOGGER.debug.
However, the following works:
Rails.logger.debug 'hello world'
Then check the logs for the corresponding environment in your app's /log folder.
I have cleared my Rails app's log file with rake log:clear.
Then Rails stopped logging the errors.... the Logfile is still empty, even though errors appeared again.
Any help?
Greets,
Joern.
It might be possible that you changed the permissions on the log file by mistake, and the user you're running your webapp server with is not the same as the one that owns the logfile.
In any case, if you run 'script/console', it should warn you if it can't write to the log file. If it doesn't, then a logfile has gotta be being written somewhere.
This is the warning the console will print if it can't write to the logfile for some reason:
Rails Error: Unable to access log
file. Please ensure that
/Users/mtoledo/Projects/stackoverflow/log/development.log
exists and is chmod 0666. The log
level has been raised to WARN and the
output directed to STDERR until the
problem is fixed. Loading development
environment (Rails 3.0.0.beta4)
Also, keep in mind it will be writing to 'development.log' unless you're changing your environment, but since you said it was writing to it before I assume that's not the issue
In the end, what's, to me, the final procedure is:
chown the log files to your web user
chmod 0666 to the log files
Restart your rails setup which can be:
Passenger -> Restart nginx/apache/proxy ( service nginx/apache2 restart would suffice )
WEBRick/Rack -> Restart these one
Unicorn -> kill -9 unicorn and launch again ( -HUP or -USR2 don't seem to reload filesystem changes properly )