Module: Memolog

Extended by:
Memolog
Included in:
Memolog
Defined in:
lib/memolog.rb,
lib/memolog/version.rb

Defined Under Namespace

Modules: Init, LoggerExtension, SentryExtension Classes: RailsMiddleware, SidekiqMiddleware

Constant Summary collapse

VERSION =
"0.5.6"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#add(*args, &block) ⇒ Object



43
44
45
# File 'lib/memolog.rb', line 43

def add(*args, &block)
  logger.log(*args, &block)
end

#configure {|config| ... } ⇒ Object

Yields:



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

def configure
  yield(config) if block_given?
end

#dump(parse_json: false) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/memolog.rb', line 47

def dump(parse_json: false)
  return if logdevs.empty?

  beginning = logdevs.last.string.length - config.log_size_limit
  beginning = 0 if beginning.negative?

  dump = logdevs.last.string.slice(beginning, config.log_size_limit).presence

  dump && parse_json ? JSON.parse(dump) : dump
rescue JSON::ParserError
  dump
end

#extend_logger(other_logger) ⇒ Object



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

def extend_logger(other_logger)
  other_logger.extend(Memolog::LoggerExtension)
end

#init_middlewares!Object



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

def init_middlewares!
  Memolog::Init.init_middlewares!
end

#runObject



34
35
36
37
38
39
40
41
# File 'lib/memolog.rb', line 34

def run
  logdevs.push(StringIO.new)
  logger.instance_variable_set(:@logdev, logdevs.last)

  yield
ensure
  logdevs.pop unless config.debug
end