strelka 0.0.1.pre.244 → 0.0.1.pre.252
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/ChangeLog +57 -3
- data/Manifest.txt +3 -4
- data/Rakefile +1 -1
- data/bin/strelka +4 -7
- data/examples/.env +4 -0
- data/examples/Procfile +8 -0
- data/examples/apps/auth-demo +3 -5
- data/examples/apps/auth-demo2 +10 -9
- data/{data/strelka → examples}/apps/hello-world +1 -2
- data/examples/apps/sessions-demo +2 -2
- data/examples/config.yml +12 -1
- data/examples/gen-config.rb +5 -6
- data/examples/templates/auth-form.tmpl +4 -0
- data/examples/templates/auth-success.tmpl +3 -1
- data/lib/strelka.rb +15 -21
- data/lib/strelka/app.rb +53 -31
- data/lib/strelka/app/auth.rb +260 -132
- data/lib/strelka/app/sessions.rb +25 -31
- data/lib/strelka/authprovider/basic.rb +33 -9
- data/lib/strelka/authprovider/hostaccess.rb +1 -1
- data/lib/strelka/constants.rb +0 -11
- data/lib/strelka/cookie.rb +17 -1
- data/lib/strelka/httpresponse/negotiation.rb +1 -1
- data/lib/strelka/session/db.rb +49 -25
- data/lib/strelka/session/default.rb +39 -19
- data/spec/lib/helpers.rb +3 -24
- data/spec/strelka/app/auth_spec.rb +461 -177
- data/spec/strelka/app/sessions_spec.rb +7 -26
- data/spec/strelka/app_spec.rb +3 -3
- data/spec/strelka/authprovider/basic_spec.rb +4 -4
- data/spec/strelka/httprequest/session_spec.rb +1 -1
- data/spec/strelka/httpresponse/session_spec.rb +1 -1
- data/spec/strelka/session/db_spec.rb +6 -1
- data/spec/strelka/session/default_spec.rb +3 -3
- metadata +7 -8
- metadata.gz.sig +2 -2
- data/examples/apps/ws-echo +0 -17
- data/lib/strelka/logging.rb +0 -301
- data/spec/strelka/logging_spec.rb +0 -74
@@ -39,12 +39,7 @@ describe Strelka::App::Sessions do
|
|
39
39
|
describe "session-class loading" do
|
40
40
|
before( :all ) do
|
41
41
|
# First, hook the anonymous class up to the 'testing' name using the PluginFactory API
|
42
|
-
@test_session_class = Class.new( Strelka::Session )
|
43
|
-
class << self; attr_accessor :options; end
|
44
|
-
def self::configure( options )
|
45
|
-
@options = options
|
46
|
-
end
|
47
|
-
end
|
42
|
+
@test_session_class = Class.new( Strelka::Session )
|
48
43
|
Strelka::Session.derivatives[ 'testing' ] = @test_session_class
|
49
44
|
end
|
50
45
|
|
@@ -53,8 +48,8 @@ describe Strelka::App::Sessions do
|
|
53
48
|
end
|
54
49
|
|
55
50
|
it "has a default associated session class" do
|
56
|
-
Strelka::App::Sessions.
|
57
|
-
Strelka::App::Sessions.session_class.should
|
51
|
+
Strelka::App::Sessions.configure
|
52
|
+
Strelka::App::Sessions.session_class.should be( Strelka::Session::Default )
|
58
53
|
end
|
59
54
|
|
60
55
|
it "is can be configured to use a different session class" do
|
@@ -62,28 +57,14 @@ describe Strelka::App::Sessions do
|
|
62
57
|
Strelka::App::Sessions.session_class.should == @test_session_class
|
63
58
|
end
|
64
59
|
|
65
|
-
it "configures the configured session class with default options" do
|
66
|
-
Strelka::App::Sessions.configure( :session_class => 'testing' )
|
67
|
-
Strelka::App::Sessions.session_class.options.should == Strelka::App::Sessions::DEFAULT_OPTIONS
|
68
|
-
end
|
69
|
-
|
70
|
-
it "merges any config options for the configured session class" do
|
71
|
-
options = { 'cookie_name' => 'patience' }
|
72
|
-
Strelka::App::Sessions.configure( :session_class => 'testing', :options => options )
|
73
|
-
Strelka::App::Sessions.session_class.options.
|
74
|
-
should == Strelka::App::Sessions::DEFAULT_OPTIONS.merge( options )
|
75
|
-
end
|
76
|
-
|
77
|
-
it "uses the default session class if the config doesn't have a session section" do
|
78
|
-
Strelka::App::Sessions.configure
|
79
|
-
Strelka::App::Sessions.session_class.should be( Strelka::Session::Default )
|
80
|
-
end
|
81
|
-
|
82
60
|
end
|
83
61
|
|
84
62
|
describe "an including App" do
|
85
63
|
|
64
|
+
|
86
65
|
before( :each ) do
|
66
|
+
Strelka::App::Sessions.configure
|
67
|
+
|
87
68
|
@app = Class.new( Strelka::App ) do
|
88
69
|
self.log.info "Anonymous App class: %p" % [ self ]
|
89
70
|
self.log.info "ID constant is: %p" % [ const_defined?(:ID) ? const_get(:ID) : "(not defined)" ]
|
@@ -152,7 +133,7 @@ describe Strelka::App::Sessions do
|
|
152
133
|
it "saves the session automatically" do
|
153
134
|
req = @request_factory.get( '/foom' )
|
154
135
|
res = @app.new.handle( req )
|
155
|
-
res.cookies.should include( Strelka::Session::Default.
|
136
|
+
res.cookies.should include( Strelka::Session::Default.cookie_name )
|
156
137
|
end
|
157
138
|
|
158
139
|
end
|
data/spec/strelka/app_spec.rb
CHANGED
@@ -103,7 +103,7 @@ describe Strelka::App do
|
|
103
103
|
rabbit_path = specs[:rabbit_new].full_gem_path
|
104
104
|
giraffe_path = specs[:giraffe].full_gem_path
|
105
105
|
|
106
|
-
Dir.should_receive( :glob ).with(
|
106
|
+
Dir.should_receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
|
107
107
|
and_return( [] )
|
108
108
|
Dir.should_receive( :glob ).with( "#{giraffe_path}/data/giraffe/{apps,handlers}/**/*" ).
|
109
109
|
and_return([ "#{giraffe_path}/data/giraffe/apps/app" ])
|
@@ -128,7 +128,7 @@ describe Strelka::App do
|
|
128
128
|
gemspec = make_gemspec( 'blood-orgy', '0.0.3' )
|
129
129
|
Gem::Specification.should_receive( :each ).and_yield( gemspec ).at_least( :once )
|
130
130
|
|
131
|
-
Dir.should_receive( :glob ).with(
|
131
|
+
Dir.should_receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
|
132
132
|
and_return( [] )
|
133
133
|
Dir.should_receive( :glob ).with( "#{gemspec.full_gem_path}/data/blood-orgy/{apps,handlers}/**/*" ).
|
134
134
|
and_return([ "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ])
|
@@ -150,7 +150,7 @@ describe Strelka::App do
|
|
150
150
|
gemspec = make_gemspec( 'blood-orgy', '0.0.3' )
|
151
151
|
Gem::Specification.should_receive( :each ).and_yield( gemspec ).at_least( :once )
|
152
152
|
|
153
|
-
Dir.should_receive( :glob ).with(
|
153
|
+
Dir.should_receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
|
154
154
|
and_return( [] )
|
155
155
|
Dir.should_receive( :glob ).with( "#{gemspec.full_gem_path}/data/blood-orgy/{apps,handlers}/**/*" ).
|
156
156
|
and_return([ "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ])
|
@@ -31,8 +31,8 @@ describe Strelka::AuthProvider::Basic do
|
|
31
31
|
@app = stub( "Strelka::App", :conn => stub("Connection", :app_id => 'test-app') )
|
32
32
|
@provider = Strelka::AuthProvider.create( :basic, @app )
|
33
33
|
@config = {
|
34
|
-
|
35
|
-
|
34
|
+
:realm => 'Pern',
|
35
|
+
:users => {
|
36
36
|
"lessa" => "8wiomemUvH/+CX8UJv3Yhu+X26k=",
|
37
37
|
"f'lar" => "NSeXAe7J5TTtJUE9epdaE6ojSYk=",
|
38
38
|
}
|
@@ -70,8 +70,8 @@ describe Strelka::AuthProvider::Basic do
|
|
70
70
|
|
71
71
|
it "can be configured via the Configurability API" do
|
72
72
|
described_class.configure( @config )
|
73
|
-
described_class.realm.should == @config[
|
74
|
-
described_class.users.should == @config[
|
73
|
+
described_class.realm.should == @config[:realm]
|
74
|
+
described_class.users.should == @config[:users]
|
75
75
|
end
|
76
76
|
|
77
77
|
|
@@ -96,7 +96,7 @@ describe Strelka::HTTPRequest::Session, "-extended request" do
|
|
96
96
|
context "with a session ID" do
|
97
97
|
|
98
98
|
before( :each ) do
|
99
|
-
cookie_name = Strelka::Session::Default.
|
99
|
+
cookie_name = Strelka::Session::Default.cookie_name
|
100
100
|
@sess_id = Strelka::Session::Default.get_session_id
|
101
101
|
@req.header.cookie = "#{cookie_name}=#{@sess_id}"
|
102
102
|
end
|
@@ -110,7 +110,7 @@ describe Strelka::HTTPResponse::Session, "-extended response" do
|
|
110
110
|
context "for a request with a session ID" do
|
111
111
|
|
112
112
|
before( :each ) do
|
113
|
-
@cookie_name = Strelka::Session::Default.
|
113
|
+
@cookie_name = Strelka::Session::Default.cookie_name
|
114
114
|
@sess_id = Strelka::Session::Default.get_session_id
|
115
115
|
@req.header.cookie = "#{@cookie_name}=#{@sess_id}"
|
116
116
|
end
|
@@ -34,13 +34,17 @@ describe Strelka::Session::Db do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
before( :each ) do
|
37
|
-
|
37
|
+
Strelka.log.debug "BEFORE each"
|
38
|
+
@cookie_name = described_class.cookie_name
|
38
39
|
described_class.configure
|
40
|
+
Strelka.log.debug "/BEFORE each"
|
39
41
|
end
|
40
42
|
|
41
43
|
after( :each ) do
|
44
|
+
Strelka.log.debug "AFTER each"
|
42
45
|
described_class.db.drop_table( :sessions ) if
|
43
46
|
described_class.db.table_exists?( :sessions )
|
47
|
+
Strelka.log.debug "/AFTER each"
|
44
48
|
end
|
45
49
|
|
46
50
|
after( :all ) do
|
@@ -61,6 +65,7 @@ describe Strelka::Session::Db do
|
|
61
65
|
|
62
66
|
|
63
67
|
it "can load an existing session from the sessions table" do
|
68
|
+
Strelka.log.debug "described_class dataset: %p" % [ described_class.dataset ]
|
64
69
|
described_class.dataset.insert(
|
65
70
|
:session_id => @session_id,
|
66
71
|
:session => @session_data.to_yaml )
|
@@ -28,7 +28,7 @@ describe Strelka::Session::Default do
|
|
28
28
|
|
29
29
|
before( :each ) do
|
30
30
|
described_class.configure
|
31
|
-
@cookie_name = described_class.
|
31
|
+
@cookie_name = described_class.cookie_name
|
32
32
|
end
|
33
33
|
|
34
34
|
after( :each ) do
|
@@ -48,8 +48,8 @@ describe Strelka::Session::Default do
|
|
48
48
|
|
49
49
|
|
50
50
|
it "can be configured to store its session ID in a different cookie" do
|
51
|
-
described_class.configure( :
|
52
|
-
described_class.
|
51
|
+
described_class.configure( :cookie_name => 'buh-mahlon' )
|
52
|
+
described_class.cookie_name.should == 'buh-mahlon'
|
53
53
|
end
|
54
54
|
|
55
55
|
it "can load sessions from and save sessions to its in-memory store" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strelka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.252
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
|
37
37
|
Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
|
38
38
|
cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
-
date: 2012-05-
|
39
|
+
date: 2012-05-31 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: trollop
|
@@ -189,7 +189,7 @@ dependencies:
|
|
189
189
|
requirements:
|
190
190
|
- - ~>
|
191
191
|
- !ruby/object:Gem::Version
|
192
|
-
version: '0.
|
192
|
+
version: '0.3'
|
193
193
|
type: :runtime
|
194
194
|
prerelease: false
|
195
195
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -197,7 +197,7 @@ dependencies:
|
|
197
197
|
requirements:
|
198
198
|
- - ~>
|
199
199
|
- !ruby/object:Gem::Version
|
200
|
-
version: '0.
|
200
|
+
version: '0.3'
|
201
201
|
- !ruby/object:Gem::Dependency
|
202
202
|
name: foreman
|
203
203
|
requirement: !ruby/object:Gem::Requirement
|
@@ -364,11 +364,12 @@ files:
|
|
364
364
|
- contrib/hoetemplate/data/project/templates/top.tmpl.erb
|
365
365
|
- contrib/hoetemplate/lib/file_name.rb.erb
|
366
366
|
- contrib/hoetemplate/spec/file_name_spec.rb.erb
|
367
|
-
-
|
367
|
+
- examples/.env
|
368
|
+
- examples/Procfile
|
368
369
|
- examples/apps/auth-demo
|
369
370
|
- examples/apps/auth-demo2
|
371
|
+
- examples/apps/hello-world
|
370
372
|
- examples/apps/sessions-demo
|
371
|
-
- examples/apps/ws-echo
|
372
373
|
- examples/config.yml
|
373
374
|
- examples/gen-config.rb
|
374
375
|
- examples/static/examples.css
|
@@ -403,7 +404,6 @@ files:
|
|
403
404
|
- lib/strelka/httpresponse.rb
|
404
405
|
- lib/strelka/httpresponse/negotiation.rb
|
405
406
|
- lib/strelka/httpresponse/session.rb
|
406
|
-
- lib/strelka/logging.rb
|
407
407
|
- lib/strelka/mixins.rb
|
408
408
|
- lib/strelka/paramvalidator.rb
|
409
409
|
- lib/strelka/plugins.rb
|
@@ -442,7 +442,6 @@ files:
|
|
442
442
|
- spec/strelka/httpresponse/negotiation_spec.rb
|
443
443
|
- spec/strelka/httpresponse/session_spec.rb
|
444
444
|
- spec/strelka/httpresponse_spec.rb
|
445
|
-
- spec/strelka/logging_spec.rb
|
446
445
|
- spec/strelka/mixins_spec.rb
|
447
446
|
- spec/strelka/paramvalidator_spec.rb
|
448
447
|
- spec/strelka/plugins_spec.rb
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
��
|
2
|
-
|
1
|
+
�/��J`���=`���)��-��m��uR��T�2Z�\�"�"�-�FM
|
2
|
+
��+�� �S��m��;v������x���υ"#x�GI���)
|
data/examples/apps/ws-echo
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
#encoding: utf-8
|
4
|
-
|
5
|
-
require 'strelka'
|
6
|
-
|
7
|
-
# A demo of the WebSocketServer -- this does the same thing as the Mongrel2
|
8
|
-
# echo server, but uses the Strelka WebSocket class.
|
9
|
-
class WebSocketEchoServer < Strelka::WebSocketServer
|
10
|
-
|
11
|
-
# Use the heartbeat plugin
|
12
|
-
plugins :heartbeat
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
data/lib/strelka/logging.rb
DELETED
@@ -1,301 +0,0 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
# encoding: utf-8
|
4
|
-
|
5
|
-
require 'logger'
|
6
|
-
require 'date'
|
7
|
-
|
8
|
-
require 'strelka' unless defined?( Strelka )
|
9
|
-
require 'strelka/mixins'
|
10
|
-
|
11
|
-
|
12
|
-
# A mixin that provides a top-level logging subsystem based on Logger.
|
13
|
-
module Strelka::Logging
|
14
|
-
|
15
|
-
### Logging
|
16
|
-
# Log levels
|
17
|
-
LOG_LEVELS = {
|
18
|
-
'debug' => Logger::DEBUG,
|
19
|
-
'info' => Logger::INFO,
|
20
|
-
'warn' => Logger::WARN,
|
21
|
-
'error' => Logger::ERROR,
|
22
|
-
'fatal' => Logger::FATAL,
|
23
|
-
}.freeze
|
24
|
-
LOG_LEVEL_NAMES = LOG_LEVELS.invert.freeze
|
25
|
-
|
26
|
-
|
27
|
-
### Inclusion hook
|
28
|
-
def self::extended( mod )
|
29
|
-
super
|
30
|
-
|
31
|
-
class << mod
|
32
|
-
# the log formatter that will be used when the logging subsystem is reset
|
33
|
-
attr_accessor :default_log_formatter
|
34
|
-
|
35
|
-
# the logger that will be used when the logging subsystem is reset
|
36
|
-
attr_accessor :default_logger
|
37
|
-
|
38
|
-
# the logger that's currently in effect
|
39
|
-
attr_accessor :logger
|
40
|
-
alias_method :log, :logger
|
41
|
-
alias_method :log=, :logger=
|
42
|
-
end
|
43
|
-
|
44
|
-
mod.default_logger = mod.logger = Logger.new( $stderr )
|
45
|
-
mod.default_logger.level = case
|
46
|
-
when $DEBUG then Logger::DEBUG
|
47
|
-
when $VERBOSE then Logger::INFO
|
48
|
-
else Logger::WARN end
|
49
|
-
mod.default_log_formatter = Strelka::Logging::Formatter.new( mod.default_logger )
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
### Reset the global logger object to the default
|
54
|
-
def reset_logger
|
55
|
-
self.logger = self.default_logger
|
56
|
-
self.logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
57
|
-
self.logger.formatter = self.default_log_formatter
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
### Returns +true+ if the global logger has not been set to something other than
|
62
|
-
### the default one.
|
63
|
-
def using_default_logger?
|
64
|
-
return self.logger == self.default_logger
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
# A alternate formatter for Logger instances.
|
69
|
-
class Formatter < Logger::Formatter
|
70
|
-
|
71
|
-
# The format to output unless debugging is turned on
|
72
|
-
DEFAULT_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"
|
73
|
-
|
74
|
-
# The format to output if debugging is turned on
|
75
|
-
DEFAULT_DEBUG_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"
|
76
|
-
|
77
|
-
|
78
|
-
### Initialize the formatter with a reference to the logger so it can check for log level.
|
79
|
-
def initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) # :notnew:
|
80
|
-
@logger = logger
|
81
|
-
@format = format
|
82
|
-
@debug_format = debug
|
83
|
-
|
84
|
-
super()
|
85
|
-
end
|
86
|
-
|
87
|
-
######
|
88
|
-
public
|
89
|
-
######
|
90
|
-
|
91
|
-
# The Logger object associated with the formatter
|
92
|
-
attr_accessor :logger
|
93
|
-
|
94
|
-
# The logging format string
|
95
|
-
attr_accessor :format
|
96
|
-
|
97
|
-
# The logging format string that's used when outputting in debug mode
|
98
|
-
attr_accessor :debug_format
|
99
|
-
|
100
|
-
|
101
|
-
### Log using either the DEBUG_FORMAT if the associated logger is at ::DEBUG level or
|
102
|
-
### using FORMAT if it's anything less verbose.
|
103
|
-
def call( severity, time, progname, msg )
|
104
|
-
args = [
|
105
|
-
time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
|
106
|
-
time.usec, # %2$d
|
107
|
-
Process.pid, # %3$d
|
108
|
-
Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
|
109
|
-
severity, # %5$s
|
110
|
-
progname, # %6$s
|
111
|
-
msg # %7$s
|
112
|
-
]
|
113
|
-
|
114
|
-
if @logger.level == Logger::DEBUG
|
115
|
-
return self.debug_format % args
|
116
|
-
else
|
117
|
-
return self.format % args
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end # class Formatter
|
121
|
-
|
122
|
-
|
123
|
-
# A ANSI-colorized formatter for Logger instances.
|
124
|
-
class ColorFormatter < Logger::Formatter
|
125
|
-
|
126
|
-
# Set some ANSI escape code constants (Shamelessly stolen from Perl's
|
127
|
-
# Term::ANSIColor by Russ Allbery <rra@stanford.edu> and Zenin <zenin@best.com>
|
128
|
-
ANSI_ATTRIBUTES = {
|
129
|
-
'clear' => 0,
|
130
|
-
'reset' => 0,
|
131
|
-
'bold' => 1,
|
132
|
-
'dark' => 2,
|
133
|
-
'underline' => 4,
|
134
|
-
'underscore' => 4,
|
135
|
-
'blink' => 5,
|
136
|
-
'reverse' => 7,
|
137
|
-
'concealed' => 8,
|
138
|
-
|
139
|
-
'black' => 30, 'on_black' => 40,
|
140
|
-
'red' => 31, 'on_red' => 41,
|
141
|
-
'green' => 32, 'on_green' => 42,
|
142
|
-
'yellow' => 33, 'on_yellow' => 43,
|
143
|
-
'blue' => 34, 'on_blue' => 44,
|
144
|
-
'magenta' => 35, 'on_magenta' => 45,
|
145
|
-
'cyan' => 36, 'on_cyan' => 46,
|
146
|
-
'white' => 37, 'on_white' => 47
|
147
|
-
}
|
148
|
-
|
149
|
-
|
150
|
-
### Create a string that contains the ANSI codes specified and return it
|
151
|
-
def self::ansi_code( *attributes )
|
152
|
-
attributes.flatten!
|
153
|
-
attributes.collect! {|at| at.to_s }
|
154
|
-
return '' unless /(?:vt10[03]|xterm(?:-color)?|linux|screen)/i =~ ENV['TERM']
|
155
|
-
attributes = ANSI_ATTRIBUTES.values_at( *attributes ).compact.join(';')
|
156
|
-
|
157
|
-
if attributes.empty?
|
158
|
-
return ''
|
159
|
-
else
|
160
|
-
return "\e[%sm" % attributes
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
|
165
|
-
### Colorize the given +string+ with the specified +attributes+ and
|
166
|
-
### return it, handling line-endings, color reset, etc.
|
167
|
-
def self::colorize( *args )
|
168
|
-
string = ''
|
169
|
-
|
170
|
-
if block_given?
|
171
|
-
string = yield
|
172
|
-
else
|
173
|
-
string = args.shift
|
174
|
-
end
|
175
|
-
|
176
|
-
ending = string[/(\s)$/] || ''
|
177
|
-
string = string.rstrip
|
178
|
-
|
179
|
-
return self.ansi_code( args.flatten ) + string + self.ansi_code( 'reset' ) + ending
|
180
|
-
end
|
181
|
-
|
182
|
-
|
183
|
-
# Color settings
|
184
|
-
LEVEL_FORMATS = {
|
185
|
-
:debug => colorize( :bold, :black ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"},
|
186
|
-
:info => colorize( :normal ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
|
187
|
-
:warn => colorize( :bold, :yellow ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
|
188
|
-
:error => colorize( :red ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
|
189
|
-
:fatal => colorize( :bold, :red ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
|
190
|
-
}
|
191
|
-
|
192
|
-
|
193
|
-
### Initialize the formatter with a reference to the logger so it can check for log level.
|
194
|
-
def initialize( logger, settings={} ) # :notnew:
|
195
|
-
settings = LEVEL_FORMATS.merge( settings )
|
196
|
-
|
197
|
-
@logger = logger
|
198
|
-
@settings = settings
|
199
|
-
|
200
|
-
super()
|
201
|
-
end
|
202
|
-
|
203
|
-
######
|
204
|
-
public
|
205
|
-
######
|
206
|
-
|
207
|
-
# The Logger object associated with the formatter
|
208
|
-
attr_accessor :logger
|
209
|
-
|
210
|
-
# The formats, by level
|
211
|
-
attr_accessor :settings
|
212
|
-
|
213
|
-
|
214
|
-
### Log using the format associated with the severity
|
215
|
-
def call( severity, time, progname, msg )
|
216
|
-
args = [
|
217
|
-
time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
|
218
|
-
time.usec, # %2$d
|
219
|
-
Process.pid, # %3$d
|
220
|
-
Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
|
221
|
-
severity, # %5$s
|
222
|
-
progname, # %6$s
|
223
|
-
msg # %7$s
|
224
|
-
]
|
225
|
-
|
226
|
-
return self.settings[ severity.downcase.to_sym ] % args
|
227
|
-
end
|
228
|
-
|
229
|
-
end # class Formatter
|
230
|
-
|
231
|
-
|
232
|
-
# An alternate formatter for Logger instances that outputs +div+ HTML
|
233
|
-
# fragments.
|
234
|
-
class HtmlFormatter < Logger::Formatter
|
235
|
-
|
236
|
-
# The default HTML fragment that'll be used as the template for each log message.
|
237
|
-
HTML_LOG_FORMAT = %q{
|
238
|
-
<div class="log-message %5$s">
|
239
|
-
<span class="log-time">%1$s.%2$06d</span>
|
240
|
-
[
|
241
|
-
<span class="log-pid">%3$d</span>
|
242
|
-
/
|
243
|
-
<span class="log-tid">%4$s</span>
|
244
|
-
]
|
245
|
-
<span class="log-level">%5$s</span>
|
246
|
-
:
|
247
|
-
<span class="log-name">%6$s</span>
|
248
|
-
<span class="log-message-text">%7$s</span>
|
249
|
-
</div>
|
250
|
-
}
|
251
|
-
|
252
|
-
### Override the logging formats with ones that generate HTML fragments
|
253
|
-
def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
|
254
|
-
@logger = logger
|
255
|
-
@format = format
|
256
|
-
super()
|
257
|
-
end
|
258
|
-
|
259
|
-
|
260
|
-
######
|
261
|
-
public
|
262
|
-
######
|
263
|
-
|
264
|
-
# The HTML fragment that will be used as a format() string for the log
|
265
|
-
attr_accessor :format
|
266
|
-
|
267
|
-
|
268
|
-
### Return a log message composed out of the arguments formatted using the
|
269
|
-
### formatter's format string
|
270
|
-
def call( severity, time, progname, msg )
|
271
|
-
args = [
|
272
|
-
time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
|
273
|
-
time.usec, # %2$d
|
274
|
-
Process.pid, # %3$d
|
275
|
-
Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
|
276
|
-
severity.downcase, # %5$s
|
277
|
-
progname, # %6$s
|
278
|
-
escape_html( msg ).gsub(/\n/, '<br />') # %7$s
|
279
|
-
]
|
280
|
-
|
281
|
-
return self.format % args
|
282
|
-
end
|
283
|
-
|
284
|
-
|
285
|
-
#######
|
286
|
-
private
|
287
|
-
#######
|
288
|
-
|
289
|
-
### Escape any HTML special characters in +string+.
|
290
|
-
def escape_html( string )
|
291
|
-
return string.
|
292
|
-
gsub( '&', '&' ).
|
293
|
-
gsub( '<', '<' ).
|
294
|
-
gsub( '>', '>' )
|
295
|
-
end
|
296
|
-
|
297
|
-
end # class HtmlFormatter
|
298
|
-
|
299
|
-
|
300
|
-
end # module Strelka
|
301
|
-
|