How to print debug messages with Sinatra/Foreman? - ruby

I'm just starting out with Ruby and with the sinatra framework. I've got a setup going now with heroku and I'm totally amazed how well it works. There is just one thing that I can't figure out. How do I debug stuff? Might sound weird but I have this variable that I'd like to print out and see, preferably in the terminal or something like that. How do I do this in ruby with forman running? When I write print or puts nothing shows upp in the foreman logging...
Thanks!

If you're using Foreman, try adding a log: process to your Procfile. For Rails apps, my Procfile looks like so:
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
log: tail -f -n 0 log/development.log
You'll want to configure Sinatra to log to a file, in my example log/development.log.
Locally, Foreman will automatically spin up a log process and spit the logs out to the terminal, similar to how what you see on Heroku. On Heroku, no log process will be ran unless you manually scale it (which you don't want anyway).

Related

How to see untrimmed logs on Heroku Local

I'm running a NodeJS app on heroku local, however all my console.log statements and error messages get trimmed.
For example:
forego | starting web.1 on port 5000
web.1 | module.js:339
I don't see the full error logs. How to avoid this trimming of error messages?
heroku local will run whatever processes you tell it to in the Procfile. If you'd like to stream your development log, simply add something like log: tail -f log/development.log to your Procfile. You'll also want to make sure that you create a second Procfile (I use Procfile.dev) for this. Replace the log file path with wherever your desired log file is located.
Cheers!
Did you try?
$ heroku help local
Source: https://devcenter.heroku.com/articles/heroku-local
Is this deployed already? If so:
On terminal/bash:
$ heroku logs
On your heroku account:
1) Go to you account and then apps and then the log for that app

Procfile in Heroku

Can somebody help me regarding on how can i solve my problem on Heroku. Im new to Heroku.
This warning always appear. WARNING:No Procfile detected, using the default web server (webrick). Im using Rails 4. Thank in advance
The error itself is pretty self-explanatory. No Procfile is detected, so in your root directory create a file called Procfile.
As you stated in your comment you are using the Unicorn server so inside the Procfile put this code.
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
I am assuming you created a unicorn.rb file
push to github, push to heroku and see if that works.
The Procfile holds the command for starting the server, and any options you need to pass to that. Your app was crashing because the command to start the server was not there at all.

Stuck on heroku setup page for ruby

https://devcenter.heroku.com/articles/getting-started-with-ruby#web-rb
I'm stuck at the "write your app" part. It gives a hello world example, so I tried doing that with vim:
The web.rb file reads as follows.
require 'sinatra'
get '/' do
"hello, world"
end
But, when I try and do: heroku addons:add newrelic:stark --app web.rb,
it says failed. app not found.
I'm probably missing something "obvious" because I've actually never worked with Heroku and hardly any Ruby before. Any help would be really appreciated.
If you're at "Write Your App", you haven't created a Heroku application yet, you've only just started writing the code for it.
Adding the newrelic add-on to a non-existent heroku app would likely give you that error.
Don't get ahead of yourself, finish the tutorial on creating the Heroku application before trying to add things to it.

First Time Heroku Deploy App Can't Make Sense of Logs

This is my first time trying to deploy a small application on heroku to apply for an summer internship.
I went through the getting started guide with rails.
Here is my log, its just too much code
http://pastebin.com/QqaKVdH3
Is there something wrong with my rails app and not part of heroku?
Did I run out of dynos? I head into my apps, click on my app, and put in 2 dynos and 1 worker for my app.
I have this in my procfile, hopefully this is correct !
bundle exec unicorn -p $PORT -E $RACK_ENV
bundle exec rake jobs:work
sorry to bother you guys, I know I need to familiarize myself with the heroku docs but if someone know the answer to this, I would love the help! I will just dig into the heroku docs when I got the time.
If you need more information please let me know.
Thanks!
The error you should start with is this:
2013-05-13T19:35:12.367382+00:00 app[web.1]: E, [2013-05-13T19:35:12.367055 #137] ERROR -- : uninitialized constant SimpleForm (NameError)
After you get past that hurdle and any others, be sure to checkout the Dev Center guide on Unicorn:
Deploying Rails Applications With Unicorn

Heroku RACK_ENV says "development" on Thin, but "staging" on Unicorn

I came across this behavior and was wondering if anyone else had seen it. I have a workaround so it's not a show-stopper.
I created a new app on Heroku with a Cedar stack. When demonstrating multiple environments I added the following config var:
heroku config:add RACK_ENV=staging --app appname
I visually verified that the environment var was set, then put the following route in my simple Sinatra example:
get '/?' do
ENV['RACK_ENV']
end
When I tested locally on my laptop, I received the expected development.
When I pushed to Heroku and hit the same route on herokuapp.com I got development instead of staging.
I switched the web server from Thin to Unicorn through the Procfile and pushed the changes back up to Heroku.
Now when I hit the route, I get the expected staging.
Has anyone else seen this? My workaround on another project where I was running Thin was to key the environment off of the New Relic app name. (I didn't switch to Unicorn because I need New Relic to work and currently Cedar and New Relic and Unicorn work together).
I had the same problem with sinatra and thin on the cedar stack using heroku's example sinatra app. The RACK_ENV refuses to be set to anything but development. (Heroku seems to think that it's RACK_ENV is set, since running 'heroku config' displays the environment you set, however in the app it's always development).
The same app on the bamboo stack had no problems.
EDIT: I submitted a ticket to heroku about this and got a really quick response which fixed the bug for me:
QUOTE:
It looks like there's a small bug in our default Procfile if you're using thin. Can you create a Procfile with the following in it?
web: bundle exec thin start -R config.ru -e $RACK_ENV -p $PORT
You can also set both your RACK_ENV and RAILS_ENV to staging using the Heroku gem ... then it works as expected. I think it may be a problem with Heroku.

Resources