Class: Neovim::Logging::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/neovim/logging.rb

Direct Known Subclasses

Null, Stream

Constant Summary collapse

SUBS =
[]

Class Method Summary collapse

Class Method Details

.inherited(cls) ⇒ Object



29
30
31
# File 'lib/neovim/logging.rb', line 29

def inherited cls
  SUBS.push cls
end

.provide(str) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/neovim/logging.rb', line 33

def provide str
  opened = nil
  args = str.to_s.split ":"
  args.each { |a| a.gsub! %r/%(\h\h)/ do ($1.to_i 0x10).chr end }
  cls =
    if args.first =~ /\A\w+\z/ then
      prot = args.shift
      (SUBS.find { |s| s::NAME == prot rescue nil }) or raise "Logger not found: #{str}"
    else
      Text
    end
  dest = args.shift
  cls.open dest, **(parse_arguments args) do |i|
    opened = true
    yield i
  end
rescue  # Errno::EACCES, Errno::ENOENT
  raise unless not opened and str.notempty?
  $stderr.puts "Failed to open log file '#{str}'. Logging to stderr."
  str = nil
  retry
end