Class: Dply::CustomLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/dply/custom_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ CustomLogger

Returns a new instance of CustomLogger.



10
11
12
13
14
15
# File 'lib/dply/custom_logger.rb', line 10

def initialize(file)
  super(file)
  @level = ::Logger::INFO
  @saved_logdev = @logdev
  @trace_mode = false
end

Instance Attribute Details

#enable_markers=(value) ⇒ Object (writeonly)

Sets the attribute enable_markers

Parameters:

  • value

    the value to set the attribute enable_markers to.



8
9
10
# File 'lib/dply/custom_logger.rb', line 8

def enable_markers=(value)
  @enable_markers = value
end

#remote_mode=(value) ⇒ Object (writeonly)

Sets the attribute remote_mode

Parameters:

  • value

    the value to set the attribute remote_mode to.



8
9
10
# File 'lib/dply/custom_logger.rb', line 8

def remote_mode=(value)
  @remote_mode = value
end

#trace_mode=(value) ⇒ Object (writeonly)

Sets the attribute trace_mode

Parameters:

  • value

    the value to set the attribute trace_mode to.



8
9
10
# File 'lib/dply/custom_logger.rb', line 8

def trace_mode=(value)
  @trace_mode = value
end

Instance Method Details

#arrow(msg) ⇒ Object



44
45
46
# File 'lib/dply/custom_logger.rb', line 44

def arrow(msg)
  info "#{"\u2023".green.bold} #{msg}"
end

#bullet(msg) ⇒ Object



48
49
50
# File 'lib/dply/custom_logger.rb', line 48

def bullet(msg)
  info "#{"\u2219".bold.blue} #{msg}"
end

#command(command, mode:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dply/custom_logger.rb', line 30

def command(command, mode:)
  str = command.is_a?(Array) ? shelljoin(command) : command
  case mode
  when :arrow
    arrow str
  when :bullet
    bullet str
  when :warn
    warn str
  else
    debug str
  end
end

#format_message(severity, timestamp, progname, msg) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dply/custom_logger.rb', line 17

def format_message(severity, timestamp, progname, msg)
  case severity
  when "INFO"
    "#{msg}\n"
  when "ERROR"
    "#{severity.bold.red} #{msg}\n"
  when "WARN"
    "#{severity.downcase.bold.yellow} #{msg}\n"
  else
    "#{severity[0].bold.blue} #{msg}\n"
  end
end

#marker(msg) ⇒ Object



63
64
65
66
# File 'lib/dply/custom_logger.rb', line 63

def marker(msg)
  return if not @enable_markers
  info "dply_marker:#{msg}"
end

#remote(msg) ⇒ Object



58
59
60
61
# File 'lib/dply/custom_logger.rb', line 58

def remote(msg)
  return if not @remote_mode
  info %{dply_msg|#{msg}}
end

#trace(msg = nil) ⇒ Object



52
53
54
55
56
# File 'lib/dply/custom_logger.rb', line 52

def trace(msg = nil)
  return if not @trace_mode
  msg = yield if block_given?
  info %(#{"T".bold.blue} #{msg})
end