1#!/usr/bin/env ruby 2 3require 'logger' 4 5class MyApp < Logger::Application 6 def initialize(a, b, c) 7 super('MyApp') 8 9 # Set logDevice here. 10 logfile = 'app.log' 11 self.log = logfile 12 self.level = INFO 13 14 # Initialize your application... 15 @a = a 16 @b = b 17 @c = c 18 end 19 20 def run 21 @log.info { 'Started.' } 22 23 @log.info { "This block isn't evaled because 'debug' is not severe here." } 24 @log.debug { "Result = " << foo(0) } 25 @log.info { "So nothing is dumped." } 26 27 @log.info { "This block is evaled because 'info' is enough severe here." } 28 @log.info { "Result = " << foo(0) } 29 @log.info { "Above causes exception, so not reached here." } 30 31 @log.info { 'Finished.' } 32 end 33 34private 35 36 def foo(var) 37 1 / var 38 end 39end 40 41status = MyApp.new(1, 2, 3).start 42 43if status != 0 44 puts 'Some error(s) occurred.' 45 puts 'See "app.log".' 46end 47