Class: ScripTTY::Util::Transcript::Writer
- Inherits:
-
Object
- Object
- ScripTTY::Util::Transcript::Writer
- Defined in:
- lib/scriptty/util/transcript/writer.rb
Instance Attribute Summary collapse
-
#override_timestamp ⇒ Object
Set this to non-nil to force the next record to have a specific timestamp.
Instance Method Summary collapse
-
#client_close(message) ⇒ Object
Log client connection close.
-
#client_open(host, port) ⇒ Object
Client connection opened.
-
#client_parsed(event, bytes) ⇒ Object
Log event from the client (i.e. bytes parsed into an escape sequence, with an event fired).
- #close ⇒ Object
-
#exception(exc) ⇒ Object
Convenience function: Log an exception object.
-
#exception_backtrace(line) ⇒ Object
Log exception - single backtrace line.
-
#exception_head(klass_name, message) ⇒ Object
Log exception - header - class and message.
-
#from_client(bytes) ⇒ Object
Log bytes from the client.
-
#from_server(bytes) ⇒ Object
Log bytes from the server.
-
#info(*args) ⇒ Object
Log informational message.
-
#initialize(io) ⇒ Writer
constructor
A new instance of Writer.
-
#server_close(message) ⇒ Object
Log server connection close.
-
#server_open(host, port) ⇒ Object
Server connection opened.
-
#server_parsed(event, bytes) ⇒ Object
Log event from the server (i.e. bytes parsed into an escape sequence, with an event fired).
Constructor Details
#initialize(io) ⇒ Writer
Returns a new instance of Writer.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/scriptty/util/transcript/writer.rb', line 27 def initialize(io) @io = io @start_time = Time.now @override_timestamp = nil if block_given? begin yield self ensure close end end end |
Instance Attribute Details
#override_timestamp ⇒ Object
Set this to non-nil to force the next record to have a specific timestamp
25 26 27 |
# File 'lib/scriptty/util/transcript/writer.rb', line 25 def @override_timestamp end |
Instance Method Details
#client_close(message) ⇒ Object
Log client connection close
80 81 82 |
# File 'lib/scriptty/util/transcript/writer.rb', line 80 def client_close() write_event("Cx", ) end |
#client_open(host, port) ⇒ Object
Client connection opened
45 46 47 |
# File 'lib/scriptty/util/transcript/writer.rb', line 45 def client_open(host, port) write_event("Copen", host, port.to_s) end |
#client_parsed(event, bytes) ⇒ Object
Log event from the client (i.e. bytes parsed into an escape sequence, with an event fired)
65 66 67 |
# File 'lib/scriptty/util/transcript/writer.rb', line 65 def client_parsed(event, bytes) write_event("Cp", event.to_s, bytes) end |
#close ⇒ Object
40 41 42 |
# File 'lib/scriptty/util/transcript/writer.rb', line 40 def close @io.close end |
#exception(exc) ⇒ Object
Convenience function: Log an exception object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/scriptty/util/transcript/writer.rb', line 90 def exception(exc) klass_name = exc.class.to_s if exc.respond_to?(:message) = exc..to_s else = exc.to_s end exception_head(klass_name, ) exc.backtrace.each do |line| exception_backtrace(line) end nil end |
#exception_backtrace(line) ⇒ Object
Log exception - single backtrace line
110 111 112 |
# File 'lib/scriptty/util/transcript/writer.rb', line 110 def exception_backtrace(line) write_event("EX+", line) end |
#exception_head(klass_name, message) ⇒ Object
Log exception - header - class and message
105 106 107 |
# File 'lib/scriptty/util/transcript/writer.rb', line 105 def exception_head(klass_name, ) write_event("EXC", klass_name, ) end |
#from_client(bytes) ⇒ Object
Log bytes from the client
55 56 57 |
# File 'lib/scriptty/util/transcript/writer.rb', line 55 def from_client(bytes) write_event("C", bytes) end |
#from_server(bytes) ⇒ Object
Log bytes from the server
60 61 62 |
# File 'lib/scriptty/util/transcript/writer.rb', line 60 def from_server(bytes) write_event("S", bytes) end |
#info(*args) ⇒ Object
Log informational message
85 86 87 |
# File 'lib/scriptty/util/transcript/writer.rb', line 85 def info(*args) write_event("*", *args) end |
#server_close(message) ⇒ Object
Log server connection close
75 76 77 |
# File 'lib/scriptty/util/transcript/writer.rb', line 75 def server_close() write_event("Sx", ) end |
#server_open(host, port) ⇒ Object
Server connection opened
50 51 52 |
# File 'lib/scriptty/util/transcript/writer.rb', line 50 def server_open(host, port) write_event("Sopen", host, port.to_s) end |
#server_parsed(event, bytes) ⇒ Object
Log event from the server (i.e. bytes parsed into an escape sequence, with an event fired)
70 71 72 |
# File 'lib/scriptty/util/transcript/writer.rb', line 70 def server_parsed(event, bytes) write_event("Sp", event.to_s, bytes) end |