Class: Inprovise::Logger
- Inherits:
-
Object
- Object
- Inprovise::Logger
- Defined in:
- lib/inprovise/logger.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
Returns the value of attribute node.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Class Method Summary collapse
Instance Method Summary collapse
- #cached(cmd) ⇒ Object
- #clone_for_node(node) ⇒ Object
- #command(msg) ⇒ Object
- #execute(cmd) ⇒ Object
- #flush(stream = :stdout) ⇒ Object
- #flush_all ⇒ Object
-
#initialize(node, task) ⇒ Logger
constructor
A new instance of Logger.
- #local(cmd) ⇒ Object
- #log(msg, color = nil) ⇒ Object
- #mock_execute(cmd) ⇒ Object
- #print(msg, color = nil, stream = :stdout) ⇒ Object
- #println(msg, color = nil, stream = :stdout) ⇒ Object
- #remote(cmd) ⇒ Object
- #say(msg, color = nil, stream = :stdout) ⇒ Object
- #set_task(task) ⇒ Object
- #stderr(msg, force = false) ⇒ Object
- #stdout(msg, force = false) ⇒ Object
Constructor Details
#initialize(node, task) ⇒ Logger
Returns a new instance of Logger.
21 22 23 24 |
# File 'lib/inprovise/logger.rb', line 21 def initialize(node, task) @node = node set_task(task) end |
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node.
9 10 11 |
# File 'lib/inprovise/logger.rb', line 9 def node @node end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
10 11 12 |
# File 'lib/inprovise/logger.rb', line 10 def task @task end |
Class Method Details
.streams ⇒ Object
13 14 15 16 17 18 |
# File 'lib/inprovise/logger.rb', line 13 def streams @streams ||= ::Hash.new.extend(::MonitorMixin).merge!({ :stdout => { :ios => $stdout, :buffer => [{col: nil, ln: '', cr: false}] }, :stderr => { :ios => $stderr, :buffer => [{col: nil, ln: '', cr: false}] } }) end |
Instance Method Details
#cached(cmd) ⇒ Object
54 55 56 |
# File 'lib/inprovise/logger.rb', line 54 def cached(cmd) execute(cmd) end |
#clone_for_node(node) ⇒ Object
26 27 28 29 30 |
# File 'lib/inprovise/logger.rb', line 26 def clone_for_node(node) copy = self.dup copy.node = node copy end |
#command(msg) ⇒ Object
38 39 40 |
# File 'lib/inprovise/logger.rb', line 38 def command(msg) say(msg, :yellow) end |
#execute(cmd) ⇒ Object
46 47 48 |
# File 'lib/inprovise/logger.rb', line 46 def execute(cmd) say(cmd, :cyan) end |
#flush(stream = :stdout) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/inprovise/logger.rb', line 144 def flush(stream=:stdout) synchronize do do_flush(stream) end self end |
#flush_all ⇒ Object
151 152 153 154 155 156 |
# File 'lib/inprovise/logger.rb', line 151 def flush_all synchronize do [:stderr, :stdout].each { |stream| do_flush(stream) } end self end |
#local(cmd) ⇒ Object
42 43 44 |
# File 'lib/inprovise/logger.rb', line 42 def local(cmd) say(cmd, :bold) end |
#log(msg, color = nil) ⇒ Object
62 63 64 |
# File 'lib/inprovise/logger.rb', line 62 def log(msg, color=nil) say(msg, color) end |
#mock_execute(cmd) ⇒ Object
50 51 52 |
# File 'lib/inprovise/logger.rb', line 50 def mock_execute(cmd) execute(cmd) end |
#print(msg, color = nil, stream = :stdout) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/inprovise/logger.rb', line 158 def print(msg, color=nil, stream=:stdout) synchronize do put(msg, color, stream) do_print(stream) end self end |
#println(msg, color = nil, stream = :stdout) ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/inprovise/logger.rb', line 166 def println(msg, color=nil, stream=:stdout) synchronize do puts(msg, color, stream) do_print(stream) end self end |
#remote(cmd) ⇒ Object
58 59 60 |
# File 'lib/inprovise/logger.rb', line 58 def remote(cmd) say(cmd, :blue) end |
#say(msg, color = nil, stream = :stdout) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/inprovise/logger.rb', line 198 def say(msg, color=nil, stream=:stdout) synchronize do [:stderr, :stdout].each { |stream| do_flush(stream) } streambuf = buffer(stream) msg.to_s.scan(/([^\n]*)(\n\r|\n)?/) do |txt,sep| puts(txt) break unless sep end do_print(stream) end self end |
#set_task(task) ⇒ Object
32 33 34 35 36 |
# File 'lib/inprovise/logger.rb', line 32 def set_task(task) oldtask = @task @task = task.to_s oldtask end |