module Evesync::Log

Logging via syslog

Constants

DEFAULT_ENGINE

Default engine for logging, one of (:io, :syslog)

LEVELS

Supported levels for logging

SYSLOG

Log level mapping for syslog

SYSLOG_FACILITY
SYSLOG_OPTIONS

Public Class Methods

check_logger() click to toggle source
# File lib/evesync/log.rb, line 74
def check_logger
  init_logger unless @logger
end
engine=(engine) click to toggle source
# File lib/evesync/log.rb, line 78
def engine=(engine)
  raise UnsupportedLogEngine.new(engine) \
    unless [:syslog, :io].member? engine
  @engine = engine
end
init_logger() click to toggle source

Using syslog implementation

# File lib/evesync/log.rb, line 85
def init_logger
  @engine ||= DEFAULT_ENGINE
  prog = File.basename($PROGRAM_NAME)

  case @engine
  when :syslog
    @logger = Syslog.open(prog, SYSLOG_OPTIONS, SYSLOG_FACILITY)

  when :io
    FileUtils.mkdir_p '/var/log/evesync/'
    @logger = Logger.new("/var/log/evesync/#{prog}.log")
    @logger.formatter = proc do |sev, dtime, _prog, msg|
      time = dtime.strftime('%Y-%m-%d %H:%M:%S')
      "[#{time}] #{prog.ljust(8)} #{sev.ljust(5)}: #{msg}\n"
    end
  end

  @level  = Config[:loglevel] || :info
end
level() click to toggle source
# File lib/evesync/log.rb, line 70
def level
  @level
end
level=(lvl) click to toggle source
# File lib/evesync/log.rb, line 64
def level=(lvl)
  check_logger
  raise "Unknown level #{lvl}" unless LEVELS.include? lvl
  @level = lvl
end
to_string(*args) click to toggle source
# File lib/evesync/log.rb, line 105
def to_string(*args)
  to_s_with_space = ->(s) { "#{s} " }
  args.map(&to_s_with_space).reduce(&:+).strip
end