Tom Cloyd
1/21/2009 9:59:00 PM
Ilan Berci wrote:
> Tom Cloyd wrote:
>
>
>> opt = Readline::readline( ":: " )
>>
>> which generates this error -
>>
>
>
> please post the entire code snippet for help
>
> ilan
>
>
Sorry - I thought I'd included enough to justify my questions. Here's a
full source file, which produces the problem, minus all methods and
classes not relevant to the immediate problem -
# SetNet.rb
def main
# Set up logging
run_log = Toggle_log.new( 'logfile.txt' )
run_log.open
@log = run_log.log
logging_now = run_log.lgg
# [...]
end
class Toggle_log
attr_accessor :log, :lgg
def initialize( logFileName )
@logFileName = logFileName
end
def open
#create log file
log_main = File.open( @logFileName, File::WRONLY | File::APPEND )
@log = Logger.new( log_main )
@log.datetime_format = "%Y-%m-%d %H:%M:%S"
@lgg = true
# set logging level
@log.level = Logger::INFO # I.e., only INFO level and above will be
logged
@log.info( '===== START logging' ) # just a program place indicator
puts '> logging started, at INFO level'
end
def close
@log.info( '===== STOP logging' ) # just a program place indicator
puts '> logging stopped'
@log.close
@lgg = false
end
end
class SetLogLevel
def initialize( log )
@log = log
end
puts "> logging level options - from most to least grave -"
puts "> 5 = FATAL | 4 = ERROR | 3 = WARN | 2 = INFO | 1 - DEBUG | 0 = off"
puts "> enter choice (x - exit logging level entry)"
while true
opt = Readline::readline( ":: " )
case opt
when 'x' then break # exit
when '5' then
@log.warn( 'logging level changed to FATAL' )
@log.level = Logger::FATAL
puts '> logging level now FATAL'
break
when '4' then
@log.warn( 'logging level changed to ERROR' )
@log.level = Logger::ERROR
puts '> logging level now ERROR'
break
when '3' then
@log.warn( 'logging level changed to WARN' )
@log.level = Logger::WARN
puts '> logging level now WARN'
break
when '2' then
@log.warn( 'logging level changed to INFO' )
@log.level = Logger::INFO
puts '> logging level now INFO'
break
when '1' then
@log.warn( 'logging level changed to DEBUG' )
@log.level = Logger::DEBUG
puts '> logging level now DEBUG'
break
when '0' then
@log.warn( 'logging level changed to OFF; logging closed' )
@log.close
puts '> logging stopped'
break
else puts "> '"+opt+"' - ? [#2]"
end
end
end
%w(rubygems ruby-debug readline strscan logger fileutils).each{ |lib|
require lib }
#Debugger.start
#debugger # call to ruby-debug
main
# end file
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~