Class: GitLab::CI::Lint::Log

Inherits:
Colors
  • Object
show all
Includes:
Singleton
Defined in:
lib/gitlab/ci/lint/log.rb

Constant Summary

Constants inherited from Colors

Colors::BACKGROUD_COLORS, Colors::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Colors

colorize

Constructor Details

#initialize(log_file = "./file.log") ⇒ Log

Returns a new instance of Log.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/ci/lint/log.rb', line 12

def initialize log_file="./file.log"
  @logger = Logger.new GitLab::CI::Lint::MultiIO.new(STDOUT,
    File.open(File.exist?(log_file) ? log_file : "./file.log", "a"))

  @logger.level = Logger::INFO

  @logger.formatter = proc do |severity, datetime, progname, msg|
    datetime = "[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}]"
    case severity
      when "INFO"
        colorized_severity = self.class.colorize("#{severity}", "black", "green")
        self.class.colorize("#{colorized_severity} - #{datetime} - #{msg}\n", "black", "green")
      when "ERROR"
        colorized_severity = self.class.colorize("#{severity}", "black", "red")
        "#{colorized_severity} - #{datetime} - #{msg}\n"
    end
  end
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/gitlab/ci/lint/log.rb', line 11

def logger
  @logger
end

Instance Method Details

#debug(message, color = :green) ⇒ Object



39
40
41
# File 'lib/gitlab/ci/lint/log.rb', line 39

def debug  message, color=:green
  @logger.debug(message)
end

#error(message, color = :green) ⇒ Object



43
44
45
# File 'lib/gitlab/ci/lint/log.rb', line 43

def error message, color=:green
  @logger.error(message)
end

#info(message, color = :green) ⇒ Object



35
36
37
# File 'lib/gitlab/ci/lint/log.rb', line 35

def info message, color=:green
  @logger.info(message)
end

#set_level(level) ⇒ Object



31
32
33
# File 'lib/gitlab/ci/lint/log.rb', line 31

def set_level level
  @logger.level = level
end

#warn(message) ⇒ Object



47
48
49
# File 'lib/gitlab/ci/lint/log.rb', line 47

def warn message
  @logger.warn(message)
end