From 40689b556b14d71d550db4487794b2771f2b2f1c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 22 Dec 2011 20:46:03 -0800 Subject: [PATCH] Logging in the DataStore class --- lib/vagrant/data_store.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/data_store.rb b/lib/vagrant/data_store.rb index e98b5796d..5855335d2 100644 --- a/lib/vagrant/data_store.rb +++ b/lib/vagrant/data_store.rb @@ -1,3 +1,5 @@ +require 'log4r' + module Vagrant # The Vagrant data store is a key-value store which is persisted # as JSON in a local file which is specified in the initializer. @@ -16,6 +18,9 @@ module Vagrant attr_reader :file_path def initialize(file_path) + @logger = Log4r::Logger.new("vagrant::datastore") + @logger.info("Created: #{file_path}") + @file_path = file_path return if !file_path @@ -27,7 +32,7 @@ module Vagrant merge!(JSON.parse(f.read)) rescue JSON::ParserError # Ignore if the data is invalid in the file. - # TODO: Log here. + @logger.error("Data store contained invalid JSON. Ignoring.") end end end @@ -42,9 +47,11 @@ module Vagrant if empty? # Delete the file since an empty data store is not useful - File.delete(file_path) if File.file?(file_path) + @logger.info("Deleting data store since we're empty: #{@file_path}") + File.delete(@file_path) if File.file?(@file_path) else - File.open(file_path, "w") { |f| f.write(to_json) } + @logger.info("Committing data to data store: #{@file_path}") + File.open(@file_path, "w") { |f| f.write(to_json) } end end