T
Tom Cloyd
I've been staring at this for a couple of hours, and I cannot crack the
nut. This SHOULD work, but I'm obviously screwing up. Just cannot see
where. I'm carefully following several examples, but...I cannot get
access to my instance variables.
Here's a stripped down version of the code -
# SetNet.rb
def main
# Set up logging
run_log = Manage_log.new( 'logfile.txt' ).open
log = run_log.log
logging_now = run_log.lgg
# @logging_now = false
# @log, @logging_now = manage_log( 'open' )
end
# Creates program log file, setting default logging level of INFO.
Current logging is appended to existing log content. Closes log when
requested by user.
#
# * _op_ - Requested operation: _open_ or _close
#
class Manage_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
end
%w(rubygems ruby-debug readline strscan logger fileutils).each{ |lib|
require lib }
Debugger.start
debugger # call to ruby-debug
main
====
Demonstration of the lack of access -
Thanks!
Tom
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< (e-mail address removed) >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nut. This SHOULD work, but I'm obviously screwing up. Just cannot see
where. I'm carefully following several examples, but...I cannot get
access to my instance variables.
Here's a stripped down version of the code -
# SetNet.rb
def main
# Set up logging
run_log = Manage_log.new( 'logfile.txt' ).open
log = run_log.log
logging_now = run_log.lgg
# @logging_now = false
# @log, @logging_now = manage_log( 'open' )
end
# Creates program log file, setting default logging level of INFO.
Current logging is appended to existing log content. Closes log when
requested by user.
#
# * _op_ - Requested operation: _open_ or _close
#
class Manage_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
end
%w(rubygems ruby-debug readline strscan logger fileutils).each{ |lib|
require lib }
Debugger.start
debugger # call to ruby-debug
main
====
Demonstration of the lack of access -
I would truly appreciate someone's pointing out the problem here.$ ruby setnet-x.rb
setnet-x.rb:40
main
(rdb:1) b 4
Breakpoint 1 file setnet-x.rb, line 4
(rdb:1) c
Breakpoint 1 at setnet-x.rb:4
setnet-x.rb:4
run_log = Manage_log.new( 'logfile.txt' ).open
(rdb:1) n
setnet-x.rb:5
log = run_log.log
(rdb:1) p run_log.log
NoMethodError Exception: undefined method `log' for nil:NilClass
(rdb:1)
Thanks!
Tom
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< (e-mail address removed) >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~