diff options
| author | Luke Kanies <luke@madstop.com> | 2005-07-11 18:14:20 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-07-11 18:14:20 +0000 |
| commit | 96f3980a57f8fd24aff801420a0813bad9bb20d7 (patch) | |
| tree | caffb500e987998c29fb773869b58c335d71d382 /lib/puppet/log.rb | |
| parent | 649d59a24cf03387e58fa1d4a151fcf34e409777 (diff) | |
| download | puppet-96f3980a57f8fd24aff801420a0813bad9bb20d7.tar.gz puppet-96f3980a57f8fd24aff801420a0813bad9bb20d7.tar.xz puppet-96f3980a57f8fd24aff801420a0813bad9bb20d7.zip | |
adding Puppet#recmkdir utility function, and making sure Log and Storage create their own files and directories as necessary
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@354 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/log.rb')
| -rw-r--r-- | lib/puppet/log.rb | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb index 06d7a0650..20aaff003 100644 --- a/lib/puppet/log.rb +++ b/lib/puppet/log.rb @@ -44,6 +44,12 @@ module Puppet end end + def Log.flush + if defined? @@logfile + @@logfile.flush + end + end + def Log.create(level,*ary) msg = ary.join(" ") @@ -67,7 +73,7 @@ module Puppet end def Log.destination=(dest) - if dest == "syslog" || dest == :syslog + if dest == "syslog" or dest == :syslog unless defined? @@syslog @@syslog = Syslog.open("puppet") end @@ -76,13 +82,37 @@ module Puppet if defined? @@logfile @@logfile.close end + + @@logpath = dest + + # first make sure the directory exists + unless FileTest.exist?(File.dirname(dest)) + begin + Puppet.recmkdir(File.dirname(dest)) + Puppet.info "Creating log directory %s" % + File.dirname(dest) + rescue => detail + Log.destination = :console + Puppet.err "Could not create log directory: %s" % + detail + return + end + end + begin - @@logfile = File.open(dest,"w") + # create the log file, if it doesn't already exist + @@logfile = File.open(dest,File::WRONLY|File::CREAT|File::APPEND) rescue => detail - raise + Log.destination = :console + Puppet.err "Could not create log file: %s" % + detail + return end @@logdest = :file else + unless @@logdest == :console or @@logdest == "console" + Puppet.notice "Invalid log setting %s; setting log destination to 'console'" % @@logdest + end @@logdest = :console end end |
