Debug Rails (send to logger msg)

Hello,

I was wondering if I could sent any messages to the logger (console
command) in RoR, I saw someone do it, I just cannot remember what he
wrote.

“Console command” => when you type ruby script/server and the server
start, could I use that to debug my Web Application?

Regards,
Jamal

On Tue, Mar 06, 2007 at 09:28:46PM +0100, Jamal S. wrote :

I was wondering if I could sent any messages to the logger (console
command) in RoR, I saw someone do it, I just cannot remember what he
wrote.

Action Pack provides a logger. Have a look to ri Logger:
you can use: logger.info(‘French cheese rocks’), logger.fatal(‘Django
sucks’), … Those are writtent in log/*.log

You can also use breakpoints (ruby script/breakpointer) for debugging.


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

Pierre-Alexandre M. wrote:

On Tue, Mar 06, 2007 at 09:28:46PM +0100, Jamal S. wrote :

I was wondering if I could sent any messages to the logger (console
command) in RoR, I saw someone do it, I just cannot remember what he
wrote.

Action Pack provides a logger. Have a look to ri Logger:
you can use: logger.info(‘French cheese rocks’), logger.fatal(‘Django
sucks’), … Those are writtent in log/*.log

You can also use breakpoints (ruby script/breakpointer) for debugging.


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

I did what you wrote, but I cannot find the output anywhere on the
screen :S any other easy way to debug my web application? please :slight_smile:

Gwyn Morfey wrote:

I did what you wrote, but I cannot find the output anywhere on the
screen :S any other easy way to debug my web application? please :slight_smile:
If you’re running in development mode, the output will be written to
log/development.log. I tend to leave a terminal open running ‘tail -f
log/development.log’.

Because all output is rendered through a View, it’s not trivial to do
debug writes into the HTML itself, like you would in PHP, but the
logfile is a better approach anyway.

Gwyn.

I’m running ruby under Windows, we don’t have tail command?

I did what you wrote, but I cannot find the output anywhere on the
screen :S any other easy way to debug my web application? please :slight_smile:
If you’re running in development mode, the output will be written to
log/development.log. I tend to leave a terminal open running ‘tail -f
log/development.log’.

Because all output is rendered through a View, it’s not trivial to do
debug writes into the HTML itself, like you would in PHP, but the
logfile is a better approach anyway.

Gwyn.

Sure. If you want console debug output (so stuff gets written in the
console where you typed “ruby script/server”, just use puts .

You really should use the logging support though. logger.debug and
logger.info do that in your code.

On 3/6/07, Jamal S. [email protected] wrote:

Regards,
Jamal


Posted via http://www.ruby-forum.com/.


-Eric Price

“The greatest error in the history of searching for meaning is assuming
that
it is found outside one’s self.”

On Tue, Mar 06, 2007 at 10:05:34PM +0100, Jamal S. wrote :

I did what you wrote, but I cannot find the output anywhere on the
screen :S any other easy way to debug my web application? please :slight_smile:

└─(22:30:%)── ruby script/console

logger = Logger.new(‘log/development.log’)
=> #<Logger:0xb69fa4dc @progname=nil, @level=0,
@logdev=#<Logger::LogDevice:0xb69fa48c @shift_age=0,
@filename=“log/development.log”,
@mutex=#<Logger::LogDevice::LogDeviceMutex:0xb69fa464
@mon_entering_queue=[], @mon_count=0, @mon_owner=nil,
@mon_waiting_queue=[]>, @dev=#<File:log/development.log>,
@shift_size=1048576>, @formatter=nil,
@default_formatter=#<Logger::Formatter:0xb69fa4b4 @datetime_format=nil>>

logger.warn(‘WTF?!’)
=> true

exit

└─(1:22:31:%)── tail -1 log/development.log
WTF?!

Hope that helps.


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

Thanks :slight_smile:

On Tue, Mar 06, 2007 at 09:14:30PM -0000, Gwyn Morfey wrote :

Because all output is rendered through a View, it’s not trivial to do
debug writes into the HTML itself, like you would in PHP, but the
logfile is a better approach anyway.

You can use @debug(params) for instance.

A ugly hack would be:
logger.warn(‘poy!’) in the controller

File.read("#{RAILS_ROOT}/log/development.log") in the view :confused:

But why debug in the view? Just use breakpoints.


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

Use mTail.

Free. For windows.

– Wes

On Mar 6, 3:21 pm, Jamal S. [email protected]

On Tue, Mar 06, 2007 at 01:32:35PM -0800, wesgarrison wrote :

Free. For windows.

I guess PowerShell have a tail cmd.


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’