The logs themselves will be stored in your railsroot/
log directory. But even if you are just writing stand-alone Active Record programs (like we
have been throughout this book), you can still take advantage of the power of logging. You just
need to do a few simple configuration steps:
CHAPTER 6 ?– ACTIVE RECORD TESTING AND DEBUGGING 153
1. Define a Logger object. Log4r is a Ruby logging library that comes standard with Ruby
and is, therefore, available to all Ruby applications. Creating an instance of a logger is
as simple as adding the following line of code:
mylog = Logger.new('mylog.txt')
In the preceding example, we told the logger to record details to a file called mylog.txt,
but we could just as easily have it dump output to STDOUT. Doing that would cause the
log details to be reported to the console, as we ran our programs from a command line.
2. Associate your Logger object to your Active Record Base class. Now that we have an
instance of a Logger object, we just need to tell the Active Record Base class to use that
for logging all activity.
Pages:
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352