Skip to content

Instantly share code, notes, and snippets.

@mattscilipoti
Forked from canadaduane/log.rb
Created January 28, 2010 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattscilipoti/288921 to your computer and use it in GitHub Desktop.
Save mattscilipoti/288921 to your computer and use it in GitHub Desktop.
log in json format
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