Class: SCSSLint::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/scss_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 SCSSLint::Logger instance.

Parameters:

  • out (IO)

    the output destination.



17
18
19
# File 'lib/scss_lint/logger.rb', line 17

def initialize(out)
  @out = out
end

Instance Attribute Details

#color_enabledtrue, false

Whether colored output via ANSI escape sequences is enabled.

Returns:

  • (true, false)


6
7
8
# File 'lib/scss_lint/logger.rb', line 6

def color_enabled
  @color_enabled
end

Class Method Details

.silentSCSSLint::Logger

Creates a logger which outputs nothing.

Returns:



10
11
12
# File 'lib/scss_lint/logger.rb', line 10

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

Instance Method Details

#bold(output) ⇒ Object

Mark the specified output in bold face. If output destination is not a TTY, this is a noop.

Parameters:

  • output (String)

    the output to format



84
85
86
# File 'lib/scss_lint/logger.rb', line 84

def bold(output)
  color('1', output)
end

#bold_error(output, newline = true) ⇒ 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:

  • output (String)

    the output to send

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

    whether to append a newline



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

def bold_error(output, newline = true)
  log(bold_red(output), newline)
end

#bold_red(output) ⇒ Object

Mark the specified output in bold red. If output destination is not a TTY, this is a noop.

Parameters:

  • output (String)

    the output to format



92
93
94
# File 'lib/scss_lint/logger.rb', line 92

def bold_red(output)
  color('1;31', output)
end

#cyan(output) ⇒ Object

Mark the specified output in cyan. If output destination is not a TTY, this is a noop.

Parameters:

  • output (String)

    the output to format



132
133
134
# File 'lib/scss_lint/logger.rb', line 132

def cyan(output)
  color(36, output)
end

#error(output, newline = true) ⇒ Object

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

Parameters:

  • output (String)

    the output to send

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

    whether to append a newline



35
36
37
# File 'lib/scss_lint/logger.rb', line 35

def error(output, newline = true)
  log(red(output), newline)
end

#green(output) ⇒ Object

Mark the specified output in green. If output destination is not a TTY, this is a noop.

Parameters:

  • output (String)

    the output to format



108
109
110
# File 'lib/scss_lint/logger.rb', line 108

def green(output)
  color(32, output)
end

#info(output, newline = true) ⇒ Object

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

Parameters:

  • output (String)

    the output to send

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

    whether to append a newline



71
72
73
# File 'lib/scss_lint/logger.rb', line 71

def info(output, newline = true)
  log(cyan(output), newline)
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



25
26
27
28
# File 'lib/scss_lint/logger.rb', line 25

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

#magenta(output) ⇒ Object

Mark the specified output in magenta. If output destination is not a TTY, this is a noop.

Parameters:

  • output (String)

    the output to format



124
125
126
# File 'lib/scss_lint/logger.rb', line 124

def magenta(output)
  color(35, output)
end

#newlineObject

Print a blank line.



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

def newline
  log('')
end

#red(output) ⇒ Object

Mark the specified output in red. If output destination is not a TTY, this is a noop.

Parameters:

  • output (String)

    the output to format



100
101
102
# File 'lib/scss_lint/logger.rb', line 100

def red(output)
  color(31, output)
end

#success(output, newline = true) ⇒ Object

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

Parameters:

  • output (String)

    the output to send

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

    whether to append a newline



53
54
55
# File 'lib/scss_lint/logger.rb', line 53

def success(output, newline = true)
  log(green(output), newline)
end

#tty?true, false

Whether this logger is outputting to a TTY.

Returns:

  • (true, false)


139
140
141
# File 'lib/scss_lint/logger.rb', line 139

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

#warning(output, newline = true) ⇒ 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:

  • output (String)

    the output to send

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

    whether to append a newline



62
63
64
# File 'lib/scss_lint/logger.rb', line 62

def warning(output, newline = true)
  log(yellow(output), newline)
end

#yellow(output) ⇒ Object

Mark the specified output in yellow. If output destination is not a TTY, this is a noop.

Parameters:

  • output (String)

    the output to format



116
117
118
# File 'lib/scss_lint/logger.rb', line 116

def yellow(output)
  color(33, output)
end