Method: Puppet::Util::Logging#log_exception
- Defined in:
- lib/puppet/util/logging.rb
#log_exception(exception, message = :default, options = {}) ⇒ Object
Log an exception via Puppet.err. Will also log the backtrace if Puppet is set. Parameters:
- exception
-
an Exception to log
- message
-
an optional String overriding the message to be logged; by default, we log Exception.message.
If you pass a String here, your string will be logged instead. You may also pass nil if you don't
wish to log a message at all; in this case it is likely that you are only calling this method in order
to take advantage of the backtrace logging.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/puppet/util/logging.rb', line 51 def log_exception(exception, = :default, = {}) trace = Puppet[:trace] || [:trace] if == :default && exception.is_a?(Puppet::ParseErrorWithIssue) # Retain all detailed info and keep plain message and stacktrace separate backtrace = [] build_exception_trace(backtrace, exception, trace) Puppet::Util::Log.create({ :level => [:level] || :err, :source => log_source, :message => exception., :issue_code => exception.issue_code, :backtrace => backtrace.empty? ? nil : backtrace, :file => exception.file, :line => exception.line, :pos => exception.pos, :environment => exception.environment, :node => exception.node }.merge()) else err(format_exception(exception, , trace)) end end |