Created
March 17, 2012 01:02
-
-
Save takaheraw/2054014 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleLogger | |
attr_reader :level | |
ERROR = 1 | |
WARNING = 2 | |
INFO = 3 | |
def initialize | |
@log = File.open("log.txt", "w") | |
@level = WARNING | |
end | |
@@instance = SimpleLogger.new | |
def self.instance | |
return @@instance | |
end | |
def error(msg) | |
@log.puts(msg) | |
@log.flush | |
end | |
def warning(msg) | |
@log.puts(msg) if @level >= WARNING | |
@log.flush | |
end | |
def info(msg) | |
@log.puts(msg) if @level >= INFO | |
@log.flush | |
end | |
private_class_method :new | |
end | |
logger = SimpleLogger.instance | |
logger.error("error") | |
logger.warning("warning") | |
logger.info("info") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment