punchblock-console 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pbconsole +2 -5
- data/lib/punchblock/console/cli.rb +9 -21
- data/lib/punchblock/console/commands.rb +12 -2
- data/lib/punchblock/console/logging.rb +119 -0
- data/lib/punchblock/console/version.rb +1 -1
- data/punchblock-console.gemspec +3 -1
- metadata +33 -21
data/bin/pbconsole
CHANGED
@@ -21,11 +21,8 @@ option_parser = OptionParser.new do |opts|
|
|
21
21
|
opts.on("-d", "--rayo-domain DOMAIN", String, "Specify the domain Rayo is running on") do |d|
|
22
22
|
options[:rayo_domain] = d
|
23
23
|
end
|
24
|
-
opts.on("--
|
25
|
-
options[:
|
26
|
-
end
|
27
|
-
opts.on("--transport-log-file log/transportlog.log", String, "Specify the file to which the transport log should be written") do |tlf|
|
28
|
-
options[:transport_log_file] = tlf
|
24
|
+
opts.on("--log-file log/punchblock.log", String, "Specify the file to which the log should be written") do |lf|
|
25
|
+
options[:log_file] = lf
|
29
26
|
end
|
30
27
|
opts.on("--asterisk", "Use Asterisk") do |tlf|
|
31
28
|
options[:connection_class] = Connection::Asterisk
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'punchblock'
|
2
2
|
require 'pry'
|
3
3
|
require 'punchblock/console/commands'
|
4
|
+
require 'punchblock/console/logging'
|
4
5
|
|
5
6
|
include Punchblock
|
6
7
|
|
@@ -12,7 +13,8 @@ module PunchblockConsole
|
|
12
13
|
|
13
14
|
def initialize(options)
|
14
15
|
@options = options
|
15
|
-
|
16
|
+
PunchblockConsole::Logging.start @options.delete(:log_file)
|
17
|
+
logger.info "Starting up..."
|
16
18
|
@prompt = options.delete(:prompt)
|
17
19
|
@connection = options.delete(:connection_class).new options
|
18
20
|
@client = Client.new :connection => connection
|
@@ -20,26 +22,12 @@ module PunchblockConsole
|
|
20
22
|
|
21
23
|
[:INT, :TERM].each do |signal|
|
22
24
|
trap signal do
|
23
|
-
|
25
|
+
logger.info "Shutting down!"
|
24
26
|
client.stop
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
def setup_logging
|
30
|
-
if options.has_key? :wire_log_file
|
31
|
-
options[:wire_logger] = Logger.new options.delete(:wire_log_file)
|
32
|
-
options[:wire_logger].level = Logger::DEBUG
|
33
|
-
options[:wire_logger].debug "Starting up..."
|
34
|
-
end
|
35
|
-
|
36
|
-
if options.has_key? :transport_log_file
|
37
|
-
options[:transport_logger] = Logger.new options.delete(:transport_log_file)
|
38
|
-
options[:transport_logger].level = Logger::DEBUG
|
39
|
-
options[:transport_logger].debug "Starting up..."
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
31
|
def run
|
44
32
|
run_dispatcher
|
45
33
|
client_thread = run_client
|
@@ -52,8 +40,8 @@ module PunchblockConsole
|
|
52
40
|
begin
|
53
41
|
client.run
|
54
42
|
rescue => e
|
55
|
-
|
56
|
-
|
43
|
+
logger.error "Exception in Punchblock client thread! #{e.message}"
|
44
|
+
logger.error e.backtrace.join("\t\n")
|
57
45
|
end
|
58
46
|
end
|
59
47
|
end
|
@@ -79,10 +67,10 @@ module PunchblockConsole
|
|
79
67
|
if event.call_id
|
80
68
|
call_queues[event.call_id].push event
|
81
69
|
else
|
82
|
-
puts "Ad-hoc event: #{event.inspect}"
|
70
|
+
# puts "Ad-hoc event: #{event.inspect}"
|
83
71
|
end
|
84
72
|
else
|
85
|
-
|
73
|
+
logger.warn "Unknown event: #{event.inspect}"
|
86
74
|
end
|
87
75
|
end
|
88
76
|
end
|
@@ -96,7 +84,7 @@ module PunchblockConsole
|
|
96
84
|
queue = call_queues[offer.call_id]
|
97
85
|
call = queue.pop
|
98
86
|
|
99
|
-
puts "Incoming offer to #{offer.to} from #{offer.
|
87
|
+
puts "Incoming offer to #{offer.to} from #{offer.from} #{offer}"
|
100
88
|
|
101
89
|
PunchblockConsole::Commands.new(client, offer.call_id, queue).pry
|
102
90
|
|
@@ -28,12 +28,22 @@ module PunchblockConsole
|
|
28
28
|
write Component::Record.new(options)
|
29
29
|
end
|
30
30
|
|
31
|
-
def say(string
|
32
|
-
|
31
|
+
def say(string)
|
32
|
+
output string, :text
|
33
|
+
end
|
34
|
+
|
35
|
+
def output(string, type = :text) # :nodoc:
|
36
|
+
component = Component::Output.new(type => string)
|
33
37
|
write component
|
34
38
|
component.complete_event.resource
|
35
39
|
end
|
36
40
|
|
41
|
+
def agi(command, params = {})
|
42
|
+
component = Component::Asterisk::AGI::Command.new :name => command, :params => params
|
43
|
+
write component
|
44
|
+
puts component.complete_event.resource
|
45
|
+
end
|
46
|
+
|
37
47
|
def write(command) # :nodoc:
|
38
48
|
@client.execute_command command, :call_id => @call_id, :async => false
|
39
49
|
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'logging'
|
2
|
+
|
3
|
+
class Object
|
4
|
+
def pb_logger
|
5
|
+
logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def logger
|
9
|
+
@logger ||= ::Logging.logger[self]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module PunchblockConsole
|
14
|
+
module Logging
|
15
|
+
|
16
|
+
LOG_LEVELS = %w(TRACE DEBUG INFO WARN ERROR FATAL)
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
::Logging.color_scheme('bright',
|
21
|
+
:levels => {
|
22
|
+
:info => :green,
|
23
|
+
:warn => :yellow,
|
24
|
+
:error => :red,
|
25
|
+
:fatal => [:white, :on_red]
|
26
|
+
},
|
27
|
+
:date => :blue,
|
28
|
+
:logger => :cyan,
|
29
|
+
:message => :magenta
|
30
|
+
)
|
31
|
+
|
32
|
+
def silence!
|
33
|
+
self.logging_level = :fatal
|
34
|
+
end
|
35
|
+
|
36
|
+
def unsilence!
|
37
|
+
self.logging_level = :info
|
38
|
+
end
|
39
|
+
|
40
|
+
def reset
|
41
|
+
::Logging.reset
|
42
|
+
end
|
43
|
+
|
44
|
+
def start(log_file = nil)
|
45
|
+
opts = {
|
46
|
+
:layout => ::Logging.layouts.pattern(
|
47
|
+
:pattern => '[%d] %-5l %c: %m\n',
|
48
|
+
:color_scheme => 'bright'
|
49
|
+
)
|
50
|
+
}
|
51
|
+
self.outputters = if log_file
|
52
|
+
::Logging.appenders.file log_file, opts
|
53
|
+
else
|
54
|
+
::Logging.appenders.stdout 'stdout', opts
|
55
|
+
end
|
56
|
+
|
57
|
+
::Logging.init LOG_LEVELS
|
58
|
+
|
59
|
+
LOG_LEVELS.each do |level|
|
60
|
+
PunchblockConsole::Logging.const_defined?(level) or PunchblockConsole::Logging.const_set(level, ::Logging::LEVELS[::Logging.levelify(level)])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def logging_level=(new_logging_level)
|
65
|
+
::Logging::Logger[:root].level = new_logging_level
|
66
|
+
end
|
67
|
+
|
68
|
+
alias :level= :logging_level=
|
69
|
+
|
70
|
+
def logging_level
|
71
|
+
::Logging::Logger[:root].level
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_logger(logger_name)
|
75
|
+
::Logging::Logger[logger_name]
|
76
|
+
end
|
77
|
+
|
78
|
+
alias :level :logging_level
|
79
|
+
|
80
|
+
def sanitized_logger_name(name)
|
81
|
+
name.to_s.gsub(/\W/, '').downcase
|
82
|
+
end
|
83
|
+
|
84
|
+
def outputters=(outputters)
|
85
|
+
::Logging.logger.root.appenders = Array(outputters)
|
86
|
+
end
|
87
|
+
|
88
|
+
alias :appenders= :outputters=
|
89
|
+
|
90
|
+
def outputters
|
91
|
+
::Logging.logger.root.appenders
|
92
|
+
end
|
93
|
+
|
94
|
+
alias :appenders :outputters
|
95
|
+
|
96
|
+
def formatter=(formatter)
|
97
|
+
_set_formatter formatter
|
98
|
+
end
|
99
|
+
|
100
|
+
alias :layout= :formatter=
|
101
|
+
|
102
|
+
def formatter
|
103
|
+
::Logging.logger.root.appenders.first.layout
|
104
|
+
end
|
105
|
+
|
106
|
+
alias :layout :formatter
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def _set_formatter(formatter)
|
111
|
+
::Logging.logger.root.appenders.each do |appender|
|
112
|
+
appender.layout = formatter
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
data/punchblock-console.gemspec
CHANGED
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.7") if s.respond_to? :required_rubygems_version=
|
22
22
|
|
23
|
-
s.add_runtime_dependency %q<punchblock>, [">= 0.6.
|
23
|
+
s.add_runtime_dependency %q<punchblock>, [">= 0.6.2"]
|
24
|
+
s.add_runtime_dependency %q<logging>, [">= 1.6.1"]
|
24
25
|
|
25
26
|
s.add_development_dependency %q<bundler>, ["~> 1.0.0"]
|
26
27
|
s.add_development_dependency %q<rspec>, ["~> 2.3.0"]
|
@@ -30,4 +31,5 @@ Gem::Specification.new do |s|
|
|
30
31
|
s.add_development_dependency %q<rake>, [">= 0"]
|
31
32
|
s.add_development_dependency %q<mocha>, [">= 0"]
|
32
33
|
s.add_development_dependency %q<i18n>, [">= 0"]
|
34
|
+
|
33
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: punchblock-console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,22 +11,33 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2011-11-
|
14
|
+
date: 2011-11-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: punchblock
|
18
|
-
requirement: &
|
18
|
+
requirement: &2152231320 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.6.
|
23
|
+
version: 0.6.2
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *2152231320
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: logging
|
29
|
+
requirement: &2152227800 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.1
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *2152227800
|
27
38
|
- !ruby/object:Gem::Dependency
|
28
39
|
name: bundler
|
29
|
-
requirement: &
|
40
|
+
requirement: &2152226580 !ruby/object:Gem::Requirement
|
30
41
|
none: false
|
31
42
|
requirements:
|
32
43
|
- - ~>
|
@@ -34,10 +45,10 @@ dependencies:
|
|
34
45
|
version: 1.0.0
|
35
46
|
type: :development
|
36
47
|
prerelease: false
|
37
|
-
version_requirements: *
|
48
|
+
version_requirements: *2152226580
|
38
49
|
- !ruby/object:Gem::Dependency
|
39
50
|
name: rspec
|
40
|
-
requirement: &
|
51
|
+
requirement: &2152069700 !ruby/object:Gem::Requirement
|
41
52
|
none: false
|
42
53
|
requirements:
|
43
54
|
- - ~>
|
@@ -45,10 +56,10 @@ dependencies:
|
|
45
56
|
version: 2.3.0
|
46
57
|
type: :development
|
47
58
|
prerelease: false
|
48
|
-
version_requirements: *
|
59
|
+
version_requirements: *2152069700
|
49
60
|
- !ruby/object:Gem::Dependency
|
50
61
|
name: ci_reporter
|
51
|
-
requirement: &
|
62
|
+
requirement: &2152066520 !ruby/object:Gem::Requirement
|
52
63
|
none: false
|
53
64
|
requirements:
|
54
65
|
- - ! '>='
|
@@ -56,10 +67,10 @@ dependencies:
|
|
56
67
|
version: 1.6.3
|
57
68
|
type: :development
|
58
69
|
prerelease: false
|
59
|
-
version_requirements: *
|
70
|
+
version_requirements: *2152066520
|
60
71
|
- !ruby/object:Gem::Dependency
|
61
72
|
name: yard
|
62
|
-
requirement: &
|
73
|
+
requirement: &2152064400 !ruby/object:Gem::Requirement
|
63
74
|
none: false
|
64
75
|
requirements:
|
65
76
|
- - ~>
|
@@ -67,10 +78,10 @@ dependencies:
|
|
67
78
|
version: 0.6.0
|
68
79
|
type: :development
|
69
80
|
prerelease: false
|
70
|
-
version_requirements: *
|
81
|
+
version_requirements: *2152064400
|
71
82
|
- !ruby/object:Gem::Dependency
|
72
83
|
name: rcov
|
73
|
-
requirement: &
|
84
|
+
requirement: &2152050240 !ruby/object:Gem::Requirement
|
74
85
|
none: false
|
75
86
|
requirements:
|
76
87
|
- - ! '>='
|
@@ -78,10 +89,10 @@ dependencies:
|
|
78
89
|
version: '0'
|
79
90
|
type: :development
|
80
91
|
prerelease: false
|
81
|
-
version_requirements: *
|
92
|
+
version_requirements: *2152050240
|
82
93
|
- !ruby/object:Gem::Dependency
|
83
94
|
name: rake
|
84
|
-
requirement: &
|
95
|
+
requirement: &2152041480 !ruby/object:Gem::Requirement
|
85
96
|
none: false
|
86
97
|
requirements:
|
87
98
|
- - ! '>='
|
@@ -89,10 +100,10 @@ dependencies:
|
|
89
100
|
version: '0'
|
90
101
|
type: :development
|
91
102
|
prerelease: false
|
92
|
-
version_requirements: *
|
103
|
+
version_requirements: *2152041480
|
93
104
|
- !ruby/object:Gem::Dependency
|
94
105
|
name: mocha
|
95
|
-
requirement: &
|
106
|
+
requirement: &2152039040 !ruby/object:Gem::Requirement
|
96
107
|
none: false
|
97
108
|
requirements:
|
98
109
|
- - ! '>='
|
@@ -100,10 +111,10 @@ dependencies:
|
|
100
111
|
version: '0'
|
101
112
|
type: :development
|
102
113
|
prerelease: false
|
103
|
-
version_requirements: *
|
114
|
+
version_requirements: *2152039040
|
104
115
|
- !ruby/object:Gem::Dependency
|
105
116
|
name: i18n
|
106
|
-
requirement: &
|
117
|
+
requirement: &2152037560 !ruby/object:Gem::Requirement
|
107
118
|
none: false
|
108
119
|
requirements:
|
109
120
|
- - ! '>='
|
@@ -111,7 +122,7 @@ dependencies:
|
|
111
122
|
version: '0'
|
112
123
|
type: :development
|
113
124
|
prerelease: false
|
114
|
-
version_requirements: *
|
125
|
+
version_requirements: *2152037560
|
115
126
|
description: This gem provides a simple interactive console for troubleshooting and
|
116
127
|
debugging the Rayo protocol via Punchblock.
|
117
128
|
email: punchblock@adhearsion.com
|
@@ -128,6 +139,7 @@ files:
|
|
128
139
|
- bin/pbconsole
|
129
140
|
- lib/punchblock/console/cli.rb
|
130
141
|
- lib/punchblock/console/commands.rb
|
142
|
+
- lib/punchblock/console/logging.rb
|
131
143
|
- lib/punchblock/console/version.rb
|
132
144
|
- punchblock-console.gemspec
|
133
145
|
homepage: https://github.com/adhearsion/punchblock
|