Class: MarkdownLoggingProxy::MarkdownLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_logging_proxy/markdown_logger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location, backtrace: true) ⇒ MarkdownLogger

Returns a new instance of MarkdownLogger.



10
11
12
13
14
15
# File 'lib/markdown_logging_proxy/markdown_logger.rb', line 10

def initialize(location, backtrace: true)
  @created_at = Time.now
  @std_logger = create_logger(location)
  @heading_level = 1
  @backtrace = backtrace
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



8
9
10
# File 'lib/markdown_logging_proxy/markdown_logger.rb', line 8

def backtrace
  @backtrace
end

#created_atObject (readonly)

Returns the value of attribute created_at.



8
9
10
# File 'lib/markdown_logging_proxy/markdown_logger.rb', line 8

def created_at
  @created_at
end

#heading_levelObject (readonly)

Returns the value of attribute heading_level.



8
9
10
# File 'lib/markdown_logging_proxy/markdown_logger.rb', line 8

def heading_level
  @heading_level
end

#std_loggerObject (readonly)

Returns the value of attribute std_logger.



8
9
10
# File 'lib/markdown_logging_proxy/markdown_logger.rb', line 8

def std_logger
  @std_logger
end

Class Method Details

.build(location, **options) ⇒ Object



3
4
5
6
# File 'lib/markdown_logging_proxy/markdown_logger.rb', line 3

def self.build(location, **options)
  return location if location.is_a?(MarkdownLogger)
  new(location, **options)
end

Instance Method Details

#inspect_backtrace(ignore = 4) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/markdown_logging_proxy/markdown_logger.rb', line 22

def inspect_backtrace(ignore = 4)
  return unless backtrace
  lines =
    case backtrace
    when true then caller(ignore)
    when Regexp then caller(ignore).grep(backtrace)
    else
      []
    end
  <<~MSG.chomp

    Backtrace:

    #{lines.map { |l| "* #{l.chop}`" }.join("\n")}
  MSG
end

#log(level, heading = 3, msg) ⇒ Object



17
18
19
20
# File 'lib/markdown_logging_proxy/markdown_logger.rb', line 17

def log(level, heading = 3, msg)
  @heading_level = heading
  std_logger.send(level, msg)
end