I can't figure this out for the life of me...
The code below is for a simple logger class I wrote to go along with a personal project. To avoid having to write a ton of code I overrode method_missing thereby allowing calls like "logger_instance.emergency('emergency error text')".
For whatever reason, when method_missing-based calls are made, nothing happens. The code doesn't hang or crash, it just seems to skip right over the logging code and return. No errors are thrown that I can see, and it's really starting to bother me. Ideas?
class Utility::Log
LOG_FILE = './operator_log.txt'
def initialize
end
def method_missing(level, *mesg)
log(mesg[0], level.capitalize)
end
def log(mesg, level = 'NOTICE')
_new
@logger.write(Time.now + "::#{level}::" + mesg + "\n")
_close
end
private
def _new
if File.file?(LOG_FILE)
@logger = File.open(LOG_FILE, 'a')
end
end
def _close
@logger.close
end
end