chrome_logger 0.1.0
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/.gitignore +17 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +11 -0
- data/chrome_logger.gemspec +25 -0
- data/example/config.ru +26 -0
- data/lib/chrome_logger/console.rb +49 -0
- data/lib/chrome_logger/railtie.rb +10 -0
- data/lib/chrome_logger/serializer.rb +33 -0
- data/lib/chrome_logger/version.rb +3 -0
- data/lib/chrome_logger.rb +30 -0
- data/test/chrome_logger/console_test.rb +7 -0
- data/test/chrome_logger/serializer_test.rb +7 -0
- data/test/chrome_logger_test.rb +7 -0
- data/test/test_helper.rb +14 -0
- metadata +99 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ryan Cook
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# ChromeLogger
|
2
|
+
|
3
|
+
A Ruby library that implements the [Chrome Logger](http://craig.is/writing/chrome-logger) specification as Rack middleware.
|
4
|
+
|
5
|
+
See [the example](https://github.com/cookrn/chrome_logger/blob/master/example/config.ru).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'chrome_logger'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install chrome_logger
|
20
|
+
|
21
|
+
## Installation on Rails
|
22
|
+
|
23
|
+
You probably only want it in certain environments. For `development`, add the following to your `development` group in your `Gemfile`:
|
24
|
+
|
25
|
+
gem 'chrome_logger' , :require => 'chrome_logger/railtie'
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
`env['console']` -- That's all she wrote!
|
30
|
+
|
31
|
+
It's just Rack middleware. Check out `example/config.ru`.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chrome_logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'chrome_logger'
|
8
|
+
spec.version = ChromeLogger::VERSION
|
9
|
+
spec.authors = ['Ryan Cook']
|
10
|
+
spec.email = ['cookrn@gmail.com']
|
11
|
+
spec.description = %q{Ruby library that implements the ChromeLogger spec on Rack}
|
12
|
+
spec.summary = %Q{#{ spec.name } v#{ spec.version }}
|
13
|
+
spec.homepage = 'https://github.com/cookrn/chrome_logger-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'multi_json' , '>= 1.3.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'minitest'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
data/example/config.ru
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'chrome_logger'
|
2
|
+
use ChromeLogger
|
3
|
+
|
4
|
+
app = lambda do | env |
|
5
|
+
env['console'].group 'BIG GROUP'
|
6
|
+
env['console'].log 'hi' , 'there'
|
7
|
+
env['console'].log [ 'now' , 'what' ]
|
8
|
+
env['console'].log( { :key => 1234 } )
|
9
|
+
env['console'].group_end
|
10
|
+
|
11
|
+
# Optionally use either signature
|
12
|
+
env['console'].groupCollapsed 'ANOTHER BIG GROUP'
|
13
|
+
# env['console'].group_collapsed 'ANOTHER BIG GROUP'
|
14
|
+
|
15
|
+
env['console'].log 'yet' , 'again'
|
16
|
+
env['console'].log [ 'wut' , 'wut' ]
|
17
|
+
env['console'].log( { :key => 7890 } )
|
18
|
+
|
19
|
+
# Optionally use other signature
|
20
|
+
env['console'].groupEnd
|
21
|
+
# env['console'].group_end
|
22
|
+
|
23
|
+
[ 200 , {} , [] ]
|
24
|
+
end
|
25
|
+
|
26
|
+
run app
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class ChromeLogger
|
2
|
+
class Console
|
3
|
+
attr_reader :log_items
|
4
|
+
|
5
|
+
def self.logger_for( *kinds )
|
6
|
+
kinds.each do | kind |
|
7
|
+
class_eval <<-___
|
8
|
+
def #{ kind }( *args )
|
9
|
+
add_log_items '#{ kind }' , *args
|
10
|
+
end
|
11
|
+
___
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@log_items = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_log_items( level , *args )
|
20
|
+
backtrace = caller[ 1 ] # 2 up!
|
21
|
+
item = [ args , backtrace , level ]
|
22
|
+
@log_items << item
|
23
|
+
end
|
24
|
+
|
25
|
+
def data
|
26
|
+
{
|
27
|
+
'version' => ChromeLogger::VERSION,
|
28
|
+
'columns' => [ 'log' , 'backtrace' , 'type' ],
|
29
|
+
'rows' => log_items
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
logger_for \
|
34
|
+
:error,
|
35
|
+
:group,
|
36
|
+
:groupCollapsed,
|
37
|
+
:groupEnd,
|
38
|
+
:info,
|
39
|
+
:warn
|
40
|
+
|
41
|
+
alias_method :group_collapsed , :groupCollapsed
|
42
|
+
alias_method :group_end , :groupEnd
|
43
|
+
|
44
|
+
# custom to let chrome plugin decide default
|
45
|
+
def log( *args )
|
46
|
+
add_log_items '' , *args
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
class ChromeLogger
|
5
|
+
class Serializer
|
6
|
+
attr_reader :console
|
7
|
+
|
8
|
+
def self.serialize( console )
|
9
|
+
serializer = new console
|
10
|
+
serializer.serialize
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize( console )
|
14
|
+
@console = console
|
15
|
+
end
|
16
|
+
|
17
|
+
def serialize
|
18
|
+
to_base64 to_utf8( to_json console.data )
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_base64( utf8_encoded_json )
|
22
|
+
Base64.encode64 utf8_encoded_json
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_json( data )
|
26
|
+
MultiJson.dump data
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_utf8( json )
|
30
|
+
json.encode 'UTF-8'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'chrome_logger/console'
|
2
|
+
require 'chrome_logger/serializer'
|
3
|
+
require 'chrome_logger/version'
|
4
|
+
|
5
|
+
class ChromeLogger
|
6
|
+
attr_accessor :app
|
7
|
+
|
8
|
+
DEFAULT_ENV_NAME = 'console'
|
9
|
+
HEADER = 'X-ChromeLogger-Data'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :env_name
|
13
|
+
end
|
14
|
+
@env_name ||= DEFAULT_ENV_NAME
|
15
|
+
|
16
|
+
def initialize( app )
|
17
|
+
@app = app
|
18
|
+
end
|
19
|
+
|
20
|
+
def call( env )
|
21
|
+
env[ env_name ] = Console.new
|
22
|
+
status , headers , response = app.call env
|
23
|
+
headers[ HEADER ] = Serializer.serialize env[ env_name ]
|
24
|
+
[ status , headers , response ]
|
25
|
+
end
|
26
|
+
|
27
|
+
def env_name
|
28
|
+
self.class.env_name
|
29
|
+
end
|
30
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chrome_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Cook
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: &70225244585900 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70225244585900
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70225244584980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70225244584980
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70225244583980 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70225244583980
|
47
|
+
description: Ruby library that implements the ChromeLogger spec on Rack
|
48
|
+
email:
|
49
|
+
- cookrn@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- chrome_logger.gemspec
|
60
|
+
- example/config.ru
|
61
|
+
- lib/chrome_logger.rb
|
62
|
+
- lib/chrome_logger/console.rb
|
63
|
+
- lib/chrome_logger/railtie.rb
|
64
|
+
- lib/chrome_logger/serializer.rb
|
65
|
+
- lib/chrome_logger/version.rb
|
66
|
+
- test/chrome_logger/console_test.rb
|
67
|
+
- test/chrome_logger/serializer_test.rb
|
68
|
+
- test/chrome_logger_test.rb
|
69
|
+
- test/test_helper.rb
|
70
|
+
homepage: https://github.com/cookrn/chrome_logger-ruby
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.16
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: chrome_logger v0.1.0
|
95
|
+
test_files:
|
96
|
+
- test/chrome_logger/console_test.rb
|
97
|
+
- test/chrome_logger/serializer_test.rb
|
98
|
+
- test/chrome_logger_test.rb
|
99
|
+
- test/test_helper.rb
|