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 --- Gemfile.lock | 2 ++ bin/tapicero | 1 + config/default.yaml | 5 +++-- 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 +++--- tapicero.gemspec | 1 + 9 files changed, 51 insertions(+), 15 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f0ad9ca..f9bfda6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,6 +4,7 @@ PATH tapicero (0.1.0) couchrest (~> 1.1.3) daemons + syslog_logger (~> 2.0.0) yajl-ruby GEM @@ -24,6 +25,7 @@ GEM rake (10.1.0) rest-client (1.6.7) mime-types (>= 1.16) + syslog_logger (2.0.1) yajl-ruby (1.1.0) PLATFORMS diff --git a/bin/tapicero b/bin/tapicero index d3b9d78..9a5a7ee 100755 --- a/bin/tapicero +++ b/bin/tapicero @@ -26,6 +26,7 @@ end # Graceful Ctrl-C Signal.trap("SIGINT") do + Tapicero.logger.warn "Received SIGINT - stopping tapicero" puts "\nQuit - leaving tapicero" exit end diff --git a/config/default.yaml b/config/default.yaml index e1ba45b..4cb40ea 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -30,5 +30,6 @@ security: # a restart: seq_file: "/var/log/leap/tapicero.seq" -# log file - Once we use a logger rather than writing to stdout we'll use this: -# log_file: "/var/log/leap/tapicero.log" +# Log to this file instead of syslog: +# log_file: "/var/leap/log/tapicero.log" +log_level: info 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) diff --git a/tapicero.gemspec b/tapicero.gemspec index 352e1a8..dd3a4ca 100644 --- a/tapicero.gemspec +++ b/tapicero.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| s.add_dependency "couchrest", "~> 1.1.3" s.add_dependency "daemons" s.add_dependency "yajl-ruby" + s.add_dependency "syslog_logger", "~> 2.0.0" s.add_development_dependency "minitest", "~> 3.2.0" s.add_development_dependency "mocha" s.add_development_dependency "rake" -- cgit v1.2.3 From 27ad1b6d833213cf50edb1d3dab60abe243be123 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 27 Sep 2013 09:05:52 +0200 Subject: clarify comment for log_file config setting --- config/default.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/default.yaml b/config/default.yaml index 4cb40ea..cb6a2be 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -30,6 +30,6 @@ security: # a restart: seq_file: "/var/log/leap/tapicero.seq" -# Log to this file instead of syslog: +# Configure log_file like this if you want to log to a file instead of syslog: # log_file: "/var/leap/log/tapicero.log" log_level: info -- cgit v1.2.3