[FACT-750] Add pluggable logging Created: 2014/10/28  Updated: 2015/01/22  Resolved: 2014/11/18

Status: Closed
Project: Facter
Component/s: None
Affects Version/s: None
Fix Version/s: FACT 2.4.0

Type: Improvement Priority: Normal
Reporter: Kylo Ginsberg Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Blocks
blocks PUP-2927 Facter logs should be surfaced during... Closed
Template:
Epic Link: JSON All The Things!
Story Points: 2
Sprint: Platform Client 2014-11-26

 Description   

This will allow, say, puppet to register logging routines for facter debug/warning messages.



 Comments   
Comment by Kylo Ginsberg [ 2014/11/18 ]

Peter Huene comments on FR for this? I guess the options are to wait for the PUP ticket or write a little ruby wrapper?

Comment by Peter Huene [ 2014/11/18 ]

A custom fact could be used to test it; there's nothing stopping a custom fact from registering an on_message block and calling Facter.[debug|debugonce|warn|warnonce] and verifying the log message is passed correctly and at the correct level. Note for review: Ruby will only log to debug, info (for timings), and warning levels. The additional levels mentioned in the doc comments are for future compatibility with native facter.

Comment by Kurt Wall [ 2014/11/18 ]

Verified in master at SHA=38d81191081effa8d0d8cc7c411c6c5b7769da02. Given a block, Facter.on_message executes it if Facter.warn or Facter.debug is called:

# /tmp/jenny.rb
Facter.on_message do
  puts "In log plugin"
end
 
Facter.add(:jenny) do
  setcode do
    if ENV['DEBUG']
      Facter.warn
    else
      jenny = {'your_name' => 'Jenny', 'your_number' => '867-5309'}
    end
  end
end
 
# ( export DEBUG FACTERLIB=/tmp && bundle exec facter jenny )
{"your_number"=>"867-5309", "your_name"=>"Jenny"}
# ( export DEBUG=1 FACTERLIB=/tmp && bundle exec facter jenny )
In log plugin
#

Conversely, given an empty block, Facter.on_message does not log output if Facter.warn or Facter.debug is called:

# /tmp/jenny.rb
Facter.on_message { }
 
Facter.add(:jenny) do
  setcode do
    if ENV['DEBUG']
      Facter.warn
    else
      jenny = {'your_name' => 'Jenny', 'your_number' => '867-5309'}
    end
  end
end
 
# ( export DEBUG FACTERLIB=/tmp && bundle exec facter jenny )
{"your_number"=>"867-5309", "your_name"=>"Jenny"}
# ( export DEBUG=1 FACTERLIB=/tmp && bundle exec facter jenny )
 
#

Comment by Kurt Wall [ 2014/11/18 ]

Resolved per previous comment.

Comment by William Hopper [ 2015/01/22 ]

Released in Facter 2.4.0.

Generated at Sat Dec 14 18:36:00 PST 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.