From 377195ce83c22c3a3771565cf15f6a06f1440b06 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 25 Sep 2013 12:29:48 +0200 Subject: log to file or syslog instead of STDOUT --- lib/tapicero.rb | 7 +++++++ lib/tapicero/config.rb | 31 +++++++++++++++++++++++++++---- lib/tapicero/couch_changes.rb | 9 +++++---- lib/tapicero/user_database.rb | 4 ++-- lib/tapicero_daemon.rb | 6 +++--- 5 files changed, 44 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/tapicero.rb b/lib/tapicero.rb index 967a9a7..fd66030 100644 --- a/lib/tapicero.rb +++ b/lib/tapicero.rb @@ -5,6 +5,13 @@ unless defined? LEAP_CA_CONFIG LEAP_CA_CONFIG = '/etc/leap/tapicero.yaml' end +module Tapicero + class < exc - STDERR.puts "ERROR in file #{file_path}" + init_logger + Tapicero.logger.fatal "Error in file #{file_path}" + Tapicero.logger.fatal exc exit(1) end @@ -72,5 +89,11 @@ module Tapicero return File.expand_path(file_path, base_dir) if File.exists?(File.expand_path(file_path, base_dir)) return nil end + + def log_loaded_configs(files) + files.each do |file| + Tapicero.logger.info "Loaded config from #{file} ." + end + end end end diff --git a/lib/tapicero/couch_changes.rb b/lib/tapicero/couch_changes.rb index 55a5489..376eb11 100644 --- a/lib/tapicero/couch_changes.rb +++ b/lib/tapicero/couch_changes.rb @@ -21,8 +21,8 @@ module Tapicero end def listen - puts "listening..." - puts "Starting at sequence #{since}" + Tapicero.logger.info "listening..." + Tapicero.logger.debug "Starting at sequence #{since}" db.changes :feed => :continuous, :since => since, :heartbeat => 1000 do |hash| callbacks(hash) end @@ -44,13 +44,14 @@ module Tapicero end def read_seq(seq_filename) + Tapicero.logger.debug "Looking up sequence here: #{seq_filename}" FileUtils.touch(seq_filename) unless File.writable?(seq_filename) raise StandardError.new("Can't access sequence file") end @since = File.read(seq_filename) rescue Errno::ENOENT => e - puts "No sequence file found. Starting from scratch" + Tapicero.logger.warn "No sequence file found. Starting from scratch" end def store_seq(seq) @@ -62,7 +63,7 @@ module Tapicero # def fetch_last_seq hash = db.changes :limit => 1, :descending => true - puts "starting at seq: " + hash["last_seq"] + Tapicero.logger.info "starting at seq: " + hash["last_seq"] return hash["last_seq"] end diff --git a/lib/tapicero/user_database.rb b/lib/tapicero/user_database.rb index fcdd272..84ed300 100644 --- a/lib/tapicero/user_database.rb +++ b/lib/tapicero/user_database.rb @@ -19,8 +19,8 @@ module Tapicero def secure(security) # let's not overwrite if we have a security doc already return if secured? - puts security.to_json - puts "-> #{security_url}" + Tapicero.logger.info "Writing Security to #{security_url}" + Tapicero.logger.debug security.to_json CouchRest.put security_url, security end diff --git a/lib/tapicero_daemon.rb b/lib/tapicero_daemon.rb index a5e41eb..e38a4ad 100644 --- a/lib/tapicero_daemon.rb +++ b/lib/tapicero_daemon.rb @@ -8,14 +8,14 @@ require 'tapicero' module Tapicero - puts " * Observing #{Config.couch_host_without_password}" - puts " * Tracking #{Config.users_db_name}" + Tapicero.logger.info "Observing #{Config.couch_host_without_password}" + Tapicero.logger.info "Tracking #{Config.users_db_name}" # stream = CouchStream.new(Config.couch_host + '/' + Config.users_db_name) db = CouchRest.new(Config.couch_host).database(Config.users_db_name) users = CouchChanges.new(db, Config.seq_file) users.created do |hash| - puts "Created user " + hash['id'] + Tapicero.logger.debug "Created user " + hash['id'] db = UserDatabase.new(Config.couch_host, Config.db_prefix + hash['id']) db.create db.secure(Config.security) -- cgit v1.2.3