Class: Ichiban::Logger

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



58
59
60
# File 'lib/ichiban/logger.rb', line 58

def initialize
  @out = STDOUT
end

Class Method Details

.ansi?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/ichiban/logger.rb', line 7

def self.ansi?
  @ansi
end

Instance Method Details

#ansi?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/ichiban/logger.rb', line 11

def ansi?
  self.class.ansi?
end

#compilation(src, dst) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/ichiban/logger.rb', line 15

def compilation(src, dst)
  src = src.slice(Ichiban.project_root.length + 1..-1)
  dst = dst.slice(Ichiban.project_root.length + 1..-1)
  msg = "#{src} -> #{dst}"
  if ansi?
    msg = ANSI.color(msg, :green)
  end
  out msg
end

#deletion(src, dst = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ichiban/logger.rb', line 25

def deletion(src, dst = nil)
  src = src.slice(Ichiban.project_root.length + 1..-1)
  if dst
    dst = dst.slice(Ichiban.project_root.length + 1..-1)
  end
  if dst
    msg = "Deleted: #{src} -> #{dst}"
  else
    msg = "Deleted: #{src}"
  end
  if ansi?
    msg = ANSI.color(msg, :cyan)
  end
  out msg
end

#exception(exc) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/ichiban/logger.rb', line 41

def exception(exc)
  msg = "#{exc.class.to_s}: #{exc.message}\n" + exc.backtrace.collect { |line| '  ' + line }.join("\n")
  if ansi?
    msg = ANSI.color(msg, :red)
  end
  out msg
end

#layout(path) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/ichiban/logger.rb', line 49

def layout(path)
  path = path.slice(Ichiban.project_root.length + 1..-1)
  msg = "#{path} changed; recompiling affected pages"
  if ansi?
    msg = ANSI.color(msg, :magenta)
  end
  out msg
end

#out(msg = nil) ⇒ Object

Overloaded. Pass in a string and it writes to the output stream. Pass in nothing and it returns the output stream.



77
78
79
80
81
82
83
# File 'lib/ichiban/logger.rb', line 77

def out(msg = nil)
  if msg.nil?
    @out
  else
    @out.puts msg
  end
end

#out=(io) ⇒ Object



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

def out=(io)
  @out = io
end

#reload(path) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/ichiban/logger.rb', line 62

def reload(path)
  path = path.slice(Ichiban.project_root.length + 1..-1)
  msg = "#{path} triggered a reload"
  if ansi?
    msg = ANSI.color(msg, :magenta)
  end
  out msg
end

#script_run(path) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/ichiban/logger.rb', line 85

def script_run(path)
  path = path.slice(Ichiban.project_root.length + 1..-1)
  msg = "#{path} running"
  if ansi?
    msg = ANSI.color(msg, :magenta)
  end
  out msg
end

#warn(msg) ⇒ Object



94
95
96
97
98
99
# File 'lib/ichiban/logger.rb', line 94

def warn(msg)
  if ansi?
    msg = ANSI.color(msg, :red)
  end
  out msg
end