Module: Loggerator::Log

Extended by:
Log
Included in:
Log
Defined in:
lib/loggerator/log.rb

Overview

Don’t expose internals into included modules so name-collisions are reduced

Instance Method Summary collapse

Instance Method Details

#contexts(data) ⇒ Object



30
31
32
# File 'lib/loggerator/log.rb', line 30

def contexts(data)
  Loggerator.config.default_context.merge(request_context.merge(local_context.merge(data)))
end

#local_contextObject



6
7
8
# File 'lib/loggerator/log.rb', line 6

def local_context
  RequestStore.store[:local_context] ||= {}
end

#local_context=(h) ⇒ Object



10
11
12
# File 'lib/loggerator/log.rb', line 10

def local_context=(h)
  RequestStore.store[:local_context] = h
end

#stderrObject



26
27
28
# File 'lib/loggerator/log.rb', line 26

def stderr
  Loggerator.config.stderr
end

#stderr=(stream) ⇒ Object



22
23
24
# File 'lib/loggerator/log.rb', line 22

def stderr=(stream)
  Loggerator.config.stderr = stream
end

#stdoutObject



18
19
20
# File 'lib/loggerator/log.rb', line 18

def stdout
  Loggerator.config.stdout
end

#stdout=(stream) ⇒ Object



14
15
16
# File 'lib/loggerator/log.rb', line 14

def stdout=(stream)
  Loggerator.config.stdout = stream
end

#to_stream(stream, data, &block) ⇒ Object



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

def to_stream(stream, data, &block)
  unless block
    str = unparse(data)
    stream.print(str + "\n")
  else
    data = data.dup
    start = Time.now
    to_stream(stream, data.merge(at: 'start'))
    begin
      res = yield

      to_stream(stream, data.merge(
        at: 'finish', elapsed: (Time.now - start).to_f))
      res
    rescue
      to_stream(stream, data.merge(
        at: 'exception', elapsed: (Time.now - start).to_f))
      raise $!
    end
  end
end