-
-
Save mattscilipoti/288921 to your computer and use it in GitHub Desktop.
log in json format
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 'json' | |
$log_filename ||= File.expand_path(File.join("..", "ruby.log.json"), File.dirname(__FILE__)) | |
begin | |
if !File.exist?($log_filename) | |
File.open($log_filename, "w") do |f| | |
f.write "[" | |
end | |
end | |
rescue Exception => e | |
puts "Unable to create log file #{$log_filename}" | |
end | |
def log(msg, tags = {}) | |
tags[:msg] = msg | |
tags[:time] = Time.now | |
tags[:caller] = caller[0..2] | |
File.open($log_filename, "a") do |f| | |
f.write tags.to_json + ",\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment