Skip to content

Instantly share code, notes, and snippets.

@canadaduane
Created December 16, 2009 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save canadaduane/258122 to your computer and use it in GitHub Desktop.
Save canadaduane/258122 to your computer and use it in GitHub Desktop.
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