Class: SlimLint::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/slim_lint/logger.rb

Overview

Encapsulates all communication to an output source.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out) ⇒ Logger

Creates a new SlimLint::Logger instance.

Parameters:

  • out (IO)

    the output destination.



19
20
21
# File 'lib/slim_lint/logger.rb', line 19

def initialize(out)
  @out = out
end

Instance Attribute Details

#color_enabledtrue, false

Whether colored output via ANSI escape sequences is enabled.

Returns:

  • (true, false)


8
9
10
# File 'lib/slim_lint/logger.rb', line 8

def color_enabled
  @color_enabled
end

Class Method Details

.silentSlimLint::Logger

Creates a logger which outputs nothing.

Returns:



12
13
14
# File 'lib/slim_lint/logger.rb', line 12

def self.silent
  new(File.open('/dev/null', 'w'))
end

Instance Method Details

#bold(*args) ⇒ Object

Print the specified output in bold face. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)


36
37
38
# File 'lib/slim_lint/logger.rb', line 36

def bold(*args)
  color('1', *args)
end

#bold_error(*args) ⇒ Object

Print the specified output in a bold face and color indicative of error. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)


52
53
54
# File 'lib/slim_lint/logger.rb', line 52

def bold_error(*args)
  color('1;31', *args)
end

#error(*args) ⇒ Object

Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)


44
45
46
# File 'lib/slim_lint/logger.rb', line 44

def error(*args)
  color(31, *args)
end

#info(*args) ⇒ Object

Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)


76
77
78
# File 'lib/slim_lint/logger.rb', line 76

def info(*args)
  color(36, *args)
end

#log(output, newline = true) ⇒ Object

Print the specified output.

Parameters:

  • output (String)

    the output to send

  • newline (true, false) (defaults to: true)

    whether to append a newline



27
28
29
30
# File 'lib/slim_lint/logger.rb', line 27

def log(output, newline = true)
  @out.print(output)
  @out.print("\n") if newline
end

#newlineObject

Print a blank line.



81
82
83
# File 'lib/slim_lint/logger.rb', line 81

def newline
  log('')
end

#success(*args) ⇒ Object

Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)


60
61
62
# File 'lib/slim_lint/logger.rb', line 60

def success(*args)
  color(32, *args)
end

#tty?true, false

Whether this logger is outputting to a TTY.

Returns:

  • (true, false)


88
89
90
# File 'lib/slim_lint/logger.rb', line 88

def tty?
  @out.respond_to?(:tty?) && @out.tty?
end

#warning(*args) ⇒ Object

Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)


68
69
70
# File 'lib/slim_lint/logger.rb', line 68

def warning(*args)
  color(33, *args)
end