Skip to content

Instantly share code, notes, and snippets.

@donavanm
Created February 20, 2011 00:32
Show Gist options
  • Save donavanm/835550 to your computer and use it in GitHub Desktop.
Save donavanm/835550 to your computer and use it in GitHub Desktop.
Adds json formatted ouput for Puppet applications
# Adds json formatted ouput for Puppet applications.
# Usage: puppet agent --logdest json
# Currently there's no way to load this as a plugin, see #6522. Appending this
# method to puppet/util/log/destinations.rb works. Meh.
# Would also be nice if Puppet::Util::Log had an #attributes method for
# accessors instead of instance_variable hacks.
Puppet::Util::Log.newdesttype :json do
def handle(msg)
message = {}
msg.instance_variables.each {|v| message[v.sub("@","")] = msg.instance_variable_get(v) }
puts message.to_pson
end
end
@anthonyryan1
Copy link

There's a very usable json output mode in puppet now --logdest=logstash_event will do this without requiring patching (although it comes with a bit of boilerplate intended for logstash).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment