From: pjb@... (Pascal J. Bourguignon) Date: 2009-07-22T00:05:10+09:00 Subject: Re: Best practice question: logging Pito Salas writes: > I want to sprinkle my code (Ruby, not Rails) liberally with logging > calls so that when things go wrong I can see what happened. > [...] > Any other tips or pointers would be greatly appreciated! Ok, directly in the category "other tips", if you want to see precisely what's happening, during debugging, you could "trace" the methods. I don't know if the feature is already implemented in Ruby, but it should be possible to do so without too much difficulty. Basically, you would say: trace YourClass,:aMethod and then the method YourClass.aMethod would be modified to print tracing logs upon entering (with parameters), and exiting (with results). Tracing several methods would let you get logs such as: C/USER[134]> (e 5) 1. Trace: (E '5) 2. Trace: (O '4) 3. Trace: (E '3) 4. Trace: (O '2) 5. Trace: (E '1) 6. Trace: (O '0) 6. Trace: O ==> NIL 5. Trace: E ==> NIL 4. Trace: O ==> NIL 3. Trace: E ==> NIL 2. Trace: O ==> NIL 1. Trace: E ==> NIL NIL C/USER[135]> (e 4) 1. Trace: (E '4) 2. Trace: (O '3) 3. Trace: (E '2) 4. Trace: (O '1) 5. Trace: (E '0) 5. Trace: E ==> T 4. Trace: O ==> T 3. Trace: E ==> T 2. Trace: O ==> T 1. Trace: E ==> T T C/USER[136]> When done, it would be useful to unwrap the methods with calls such as: untrace YourClass,:aMethod -- __Pascal Bourguignon__