lib/bmc-daemon-lib/conf.rb in bmc-daemon-lib-0.13.5 vs lib/bmc-daemon-lib/conf.rb in bmc-daemon-lib-0.14.0

- old
+ new

@@ -61,22 +61,25 @@ return unless @app_root # Read the gemspec gemspec = init_from_gemspec + # Annnounce loaded context + log_conf "initialized [#{@app_name}] version [#{@app_ver}]" + #return gemspec return @app_root end def dump to_hash.to_yaml(indent: 4, useheader: true, useversion: false ) end def dump_to_logs - self.log :conf, "configuration dump" + log_conf "configuration dump" dump.lines.each do |line| - self.log :conf, "| #{line.rstrip}" + log_conf "| #{line.rstrip}" end end # Direct access to any depth def at *path @@ -90,24 +93,24 @@ # Check that we'll be able to create logfiles if ::File.exists?(logfile) # File is there, is it writable ? unless ::File.writable?(logfile) - log :conf, "logging [#{pipe}] disabled: file not writable [#{logfile}]" + log_conf "logging [#{pipe}] disabled: file not writable [#{logfile}]" return nil end else # No file here, can we create it ? logdir = ::File.dirname(logfile) unless ::File.writable?(logdir) - log :conf, "logging [#{pipe}] disabled: directory not writable [#{logdir}]" + log_conf "logging [#{pipe}] disabled: directory not writable [#{logdir}]" return nil end end # OK, return a clean file path - log :conf, "logging [#{pipe}] to [#{logfile}]" + log_conf "logging [#{pipe}] to [#{logfile}]" return logfile end # Feature testers def gem_installed? gemname @@ -180,11 +183,11 @@ def prepare_newrelic # Disable if no config present return unless self.feature?(:newrelic) # Ok, let's start - log :conf, "prepare NewRelic" + log_conf "prepare NewRelic" conf = self[:newrelic] # Enable GC profiler GC::Profiler.enable @@ -206,11 +209,11 @@ end return end # Ok, let's start - log :conf, "prepare Rollbar" + log_conf "prepare Rollbar" conf = self[:rollbar] # Configure Rollbar.configure do |config| config.enabled = true @@ -237,11 +240,11 @@ # Load app config add_config(files, @app_config) # Reload config # puts "Conf.reload: loading files: #{files.inspect}" - log :conf, "reloading from files: #{files.inspect}" + log_conf "loading configuration from: #{files.inspect}" load files: files, namespaces: { environment: @app_env } # Try to access any key to force parsing of the files self[:test35547647654856865436346453754746588586799078079876543245678654324567865432] @@ -251,16 +254,20 @@ fail ConfigOtherError, "#{e.message} \n #{e.backtrace.to_yaml}" else return to_hash end + def log_conf msg + self.log :conf, msg + end + def log origin, message printf( "%s %-14s %s \n", Time.now.strftime("%Y-%m-%d %H:%M:%S"), - origin, - message + origin.to_s, + message.to_s ) end protected @@ -315,11 +322,11 @@ return unless ::File.readable?(path) # Check if Chamber's behaviour may cause problems with hyphens basename = ::File.basename(path) if basename.include?'-' - log :conf, "WARNING: files with dashes may cause unexpected behaviour with Chamber (#{basename})" + log_conf "WARNING: files with dashes may cause unexpected behaviour with Chamber (#{basename})" end # Add it files << ::File.expand_path(path) end @@ -333,11 +340,11 @@ # Ignore if explicitely disabled return nil if specific == false # Fallback on default path if not provided, specific ||= default - specific ||= "default.log" + specific ||= "log/default.log" # Build logfile_path ::File.expand_path specific.to_s, path.to_s end @@ -350,10 +357,10 @@ # OK if it's not empty # puts "- [#{arg}]" next unless arg.to_s.empty? # Otherise, we just exit - log :conf, "FAILED: object Conf has not been initialized correctly yet" + log_conf "FAILED: object Conf has not been initialized correctly yet" exit 200 end end end