Created
April 23, 2014 20:12
-
-
Save cheeyeo/11230625 to your computer and use it in GitHub Desktop.
Ruby string template
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
require "socket" | |
class MyLogger | |
attr_accessor :format | |
def initialize | |
@format = '%<severity>s %<time>s %<host>s %<pid>s %<message>s' | |
end | |
def error(message) | |
data = { | |
message: message, | |
time: Time.now, | |
host: Socket.gethostname, | |
pid: $$, | |
severity: "ERROR" | |
} | |
printf @format, data | |
end | |
end | |
logger = MyLogger.new | |
logger.format = "%<severity>.1s %{message} %{time} %{host}" | |
logger.error "Klingons off the starboard bow!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment