class Logsly::ColorsData

Public Class Methods

new(*args, &build) click to toggle source
# File lib/logsly/colors.rb, line 30
def initialize(*args, &build)
  self.instance_exec(*args, &build)

  @properties     = properties.map{ |p| self.send(p) }
  @method         = self.method_name
  @level_settings = levels.map{ |l| self.send(l) }
  @line_settings  = levels.map{ |l| self.send("#{l}_line") }

  if has_level_settings? && has_line_settings?
    raise ArgumentError, "can't set line and level settings in the same scheme"
  end
end

Public Instance Methods

date(value = nil) click to toggle source
%d

datestamp

# File lib/logsly/colors.rb, line 104
def date(value = nil)
  @date = value if !value.nil?
  @date
end
debug(value = nil) click to toggle source

color for the level text only

# File lib/logsly/colors.rb, line 45
def debug(value = nil)
  @debug = value if !value.nil?
  @debug
end
debug_line(value = nil) click to toggle source

color for the entire log message based on the value of the log level

# File lib/logsly/colors.rb, line 72
def debug_line(value = nil)
  @debug_line = value if !value.nil?
  @debug_line
end
error(value = nil) click to toggle source
# File lib/logsly/colors.rb, line 60
def error(value = nil)
  @error = value if !value.nil?
  @error
end
error_line(value = nil) click to toggle source
# File lib/logsly/colors.rb, line 87
def error_line(value = nil)
  @error_line = value if !value.nil?
  @error_line
end
fatal(value = nil) click to toggle source
# File lib/logsly/colors.rb, line 65
def fatal(value = nil)
  @fatal = value if !value.nil?
  @fatal
end
fatal_line(value = nil) click to toggle source
# File lib/logsly/colors.rb, line 92
def fatal_line(value = nil)
  @fatal_line = value if !value.nil?
  @fatal_line
end
file(value = nil) click to toggle source
%F

filename where the logging request was issued

# File lib/logsly/colors.rb, line 140
def file(value = nil)
  @file = value if !value.nil?
  @file
end
info(value = nil) click to toggle source
# File lib/logsly/colors.rb, line 50
def info(value = nil)
  @info = value if !value.nil?
  @info
end
info_line(value = nil) click to toggle source
# File lib/logsly/colors.rb, line 77
def info_line(value = nil)
  @info_line = value if !value.nil?
  @info_line
end
line(value = nil) click to toggle source
%L

line number where the logging request was issued

# File lib/logsly/colors.rb, line 146
def line(value = nil)
  @line = value if !value.nil?
  @line
end
logger(value = nil) click to toggle source
%c

name of the logger that generate the log event

# File lib/logsly/colors.rb, line 98
def logger(value = nil)
  @logger = value if !value.nil?
  @logger
end
message(value = nil) click to toggle source
%m

the user supplied log message

# File lib/logsly/colors.rb, line 110
def message(value = nil)
  @message = value if !value.nil?
  @message
end
method_name(value = nil) click to toggle source
%M

method name where the logging request was issued

# File lib/logsly/colors.rb, line 152
def method_name(value = nil)
  @method_name = value if !value.nil?
  @method_name
end
pid(value = nil) click to toggle source
%p

PID of the current process

# File lib/logsly/colors.rb, line 116
def pid(value = nil)
  @pid = value if !value.nil?
  @pid
end
thread(value = nil) click to toggle source
%T

the name of the thread Thread.current

# File lib/logsly/colors.rb, line 128
def thread(value = nil)
  @thread = value if !value.nil?
  @thread
end
thread_id(value = nil) click to toggle source
%t

object_id of the thread

# File lib/logsly/colors.rb, line 134
def thread_id(value = nil)
  @thread_id = value if !value.nil?
  @thread_id
end
time(value = nil) click to toggle source
%r

the time in milliseconds since the program started

# File lib/logsly/colors.rb, line 122
def time(value = nil)
  @time = value if !value.nil?
  @time
end
to_scheme_opts() click to toggle source
# File lib/logsly/colors.rb, line 157
def to_scheme_opts
  Hash.new.tap do |opts|
    # set general properties
    properties.each_with_index do |property, idx|
      opts[property] = @properties[idx] if @properties[idx]
    end

    # set special properties (reserved names)
    opts[:method] = @method if @method

    # set level settings - only add :levels key if one exists
    if has_level_settings?
      opts[:levels] = {}
      levels.each_with_index do |level, idx|
        opts[:levels][level] = @level_settings[idx] if @level_settings[idx]
      end
    end

    # set line-level settings - only :lines key if one exists
    if has_line_settings?
      opts[:lines] = {}
      levels.each_with_index do |level, idx|
        opts[:lines][level] = @line_settings[idx] if @line_settings[idx]
      end
    end
  end
end
warn(value = nil) click to toggle source
# File lib/logsly/colors.rb, line 55
def warn(value = nil)
  @warn = value if !value.nil?
  @warn
end
warn_line(value = nil) click to toggle source
# File lib/logsly/colors.rb, line 82
def warn_line(value = nil)
  @warn_line = value if !value.nil?
  @warn_line
end

Private Instance Methods

has_level_settings?() click to toggle source
# File lib/logsly/colors.rb, line 187
def has_level_settings?; !@level_settings.compact.empty?; end
has_line_settings?() click to toggle source
# File lib/logsly/colors.rb, line 188
def has_line_settings?;  !@line_settings.compact.empty?;  end
levels() click to toggle source
# File lib/logsly/colors.rb, line 194
def levels
  [:debug, :info, :warn, :error, :fatal]
end
properties() click to toggle source
# File lib/logsly/colors.rb, line 190
def properties
  [:logger, :date, :message, :time, :pid, :thread, :thread_id, :file, :line]
end