summaryrefslogtreecommitdiffstats
path: root/lib/puppet/transaction
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-11-07 17:30:45 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit977595bd712bfa25c176abb3983bc81df665ea7b (patch)
tree1ae2ca7ed9c71ddbc8e7b378a6457282a8042ccd /lib/puppet/transaction
parent5776fe4e33b5bb3399a2e72d76faeffb2bba1f4e (diff)
Refactoring the Change/Event/Property interface
This gives all logging responsibility to the event, which can now produce logs identical to those produced directly by the property. At this point, the events are entirely supersets of the logs.
Diffstat (limited to 'lib/puppet/transaction')
-rw-r--r--lib/puppet/transaction/change.rb9
-rw-r--r--lib/puppet/transaction/event.rb25
2 files changed, 29 insertions, 5 deletions
diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb
index 49569d6e3..f8e2a7a82 100644
--- a/lib/puppet/transaction/change.rb
+++ b/lib/puppet/transaction/change.rb
@@ -40,8 +40,9 @@ class Puppet::Transaction::Change
property.sync
result = event()
- result.log = property.notice property.change_to_s(is, should)
+ result.message = property.change_to_s(is, should)
result.status = "success"
+ result.send_log
result
rescue => detail
puts detail.backtrace if Puppet[:trace]
@@ -50,7 +51,8 @@ class Puppet::Transaction::Change
is = property.is_to_s(is)
should = property.should_to_s(should)
- result.log = property.err "change from #{is} to #{should} failed: #{detail}"
+ result.message = "change from #{is} to #{should} failed: #{detail}"
+ result.send_log
result
end
@@ -80,8 +82,9 @@ class Puppet::Transaction::Change
def noop_event
result = event
- result.log = property.log "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)"
+ result.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)"
result.status = "noop"
+ result.send_log
return result
end
end
diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb
index abd5c8041..41e1f5130 100644
--- a/lib/puppet/transaction/event.rb
+++ b/lib/puppet/transaction/event.rb
@@ -1,11 +1,13 @@
require 'puppet/transaction'
require 'puppet/util/tagging'
+require 'puppet/util/logging'
# A simple struct for storing what happens on the system.
class Puppet::Transaction::Event
include Puppet::Util::Tagging
+ include Puppet::Util::Logging
- ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :status, :log, :node, :version, :file, :line]
+ ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :status, :message, :node, :version, :file, :line, :source_description]
attr_accessor *ATTRIBUTES
attr_writer :tags
attr_accessor :time
@@ -19,12 +21,31 @@ class Puppet::Transaction::Event
@time = Time.now
end
+ def property=(prop)
+ @property = prop.to_s
+ end
+
+ def resource=(res)
+ @resource = res.to_s
+ end
+
+ def send_log
+ super(status == "failure" ? :err : :notice, message)
+ end
+
def status=(value)
raise ArgumentError, "Event status can only be #{EVENT_STATUSES.join(', ')}" unless EVENT_STATUSES.include?(value)
@status = value
end
def to_s
- log
+ message
+ end
+
+ private
+
+ # Used by the Logging module
+ def log_source
+ source_description || property || resource
end
end