console.log 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.MIT +19 -0
- data/README.md +53 -0
- data/console.log.gemspec +14 -0
- data/lib/console.log.rb +5 -0
- data/lib/console.log/console.rb +52 -0
- data/lib/console.log/core_ext.rb +9 -0
- data/lib/console.log/middleware.rb +22 -0
- data/lib/console.log/railtie.rb +7 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 02193d327eb1d5ac7bc40a1af5bebbf334d94598
|
4
|
+
data.tar.gz: feb75e59ff9ed442b6a46d135bc072bd5f9b30d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13f63320930b0e5aee79030b3951bd45143a01740857c5aadfb1c7a105b4ebef0072f2eb9c544354d8a078bf2e9711ad7d820d318ecab4cb0906c3ffa7c3c935
|
7
|
+
data.tar.gz: 0c7d4ad09a219fe749bea274b0a0366922c8be05e33a9fc06fbcd564bd54a2b9a311f8ccabcde31ae2a8de4cc413cfca10a3f6d7300594581fae3c77a04889af
|
data/LICENSE.MIT
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Conrad Irwin <conrad@bugsnag.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
The `console.log` gem allows you to use `console.log` in your Ruby on Rails apps.
|
2
|
+
|
3
|
+
I wrote it to solve 2 problems:
|
4
|
+
1. It's hard to use rails logs for debugging because their either noisy, or completely hidden. Using
|
5
|
+
`console.log` lets you easily see only log messages in this request.
|
6
|
+
1. When working on the js for [Bugsnag](https://bugsnag.com/) I kept accidentally typing `console.log`
|
7
|
+
into Rails. Now that works!
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
1. Add `gem "console.log"` to your Gemfile.
|
12
|
+
```ruby
|
13
|
+
gem "console.log" # makes console.log available in ruby
|
14
|
+
```
|
15
|
+
2. Bundle install
|
16
|
+
```shell
|
17
|
+
bundle install
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
In rails you can now use console.log for debugging. This means you don't need
|
23
|
+
to have the rails logs open (which is hard with servers like Pow), because log
|
24
|
+
messages will go to your browser console.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
def load_user
|
28
|
+
user = User.where(email: 'foo@bar.com')
|
29
|
+
console.log user
|
30
|
+
user
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
![Screen shot](http://i.imgur.com/QJjjmjf.png)
|
35
|
+
|
36
|
+
### `console.log`
|
37
|
+
|
38
|
+
See the full documentation for
|
39
|
+
[console.log](https://developer.chrome.com/devtools/docs/console-api#consolelogobject-object),
|
40
|
+
which shows you how to use colour and various other formatting tweaks.
|
41
|
+
|
42
|
+
### `console.warn`
|
43
|
+
|
44
|
+
If you want a little yellow triangle beside your message, call `console.warn` instead of `console.log`.
|
45
|
+
|
46
|
+
### `console.error`
|
47
|
+
|
48
|
+
If you want your text to be bright red, call `console.error` instead of `console.log`.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
`console.log` is licensed under the MIT license, see LICENSE.MIT for details.
|
53
|
+
Contributions and Bug Reports welcome!
|
data/console.log.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "console.log"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.author = "Conrad Irwin"
|
6
|
+
s.email = "conrad.irwin@gmail.com"
|
7
|
+
s.license = "MIT"
|
8
|
+
s.homepage = "http://github.com/ConradIrwin/console.log"
|
9
|
+
s.summary = "Port of console.log to ruby"
|
10
|
+
s.description = "Allows you to log to the console."
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.require_path = "lib"
|
13
|
+
s.add_dependency 'lspace'
|
14
|
+
end
|
data/lib/console.log.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module ConsoleLog
|
2
|
+
|
3
|
+
class Console
|
4
|
+
def log(*args)
|
5
|
+
puts(*args)
|
6
|
+
end
|
7
|
+
|
8
|
+
alias warn log
|
9
|
+
alias error log
|
10
|
+
|
11
|
+
def assert(bool, msg)
|
12
|
+
puts msg unless bool
|
13
|
+
end
|
14
|
+
|
15
|
+
def dir(a)
|
16
|
+
puts a.inspect
|
17
|
+
end
|
18
|
+
|
19
|
+
class Buffered < Console
|
20
|
+
include Enumerable
|
21
|
+
def initialize
|
22
|
+
@buffer = []
|
23
|
+
end
|
24
|
+
|
25
|
+
[:log, :warn, :error, :assert].each do |f|
|
26
|
+
define_method(f) do |*args|
|
27
|
+
super(*args)
|
28
|
+
@buffer << [f, caller(1).first, args]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def each(*a, &b)
|
33
|
+
@buffer.each(*a, &b)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_script
|
37
|
+
"<script>#{map{ |(*call)| log_line(*call) }.join("\n")}</script>"
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def log_line(fn, caller, args)
|
43
|
+
code = "console[#{fn.to_json}].apply(console, #{args.to_json})"
|
44
|
+
file, line, _ = caller.split(":")
|
45
|
+
file = file.sub(Rails.root.to_s + "/", "")
|
46
|
+
space = "\n" * (line.to_i - 1)
|
47
|
+
comment = "\n//# sourceURL=#{file}"
|
48
|
+
"eval(#{[space, code, comment].join.to_json})".gsub("</script>", "<\\u002Fscript>")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ConsoleLog
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
LSpace.with(:console => Console::Buffered.new) do
|
9
|
+
|
10
|
+
result = @app.call(env)
|
11
|
+
_, headers, response = result
|
12
|
+
if headers['Content-Type'] =~ %r{text/html} && response.respond_to?(:body=) && LSpace[:console].any?
|
13
|
+
response.body += LSpace[:console].to_script
|
14
|
+
end
|
15
|
+
|
16
|
+
result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
include ConsoleLog::CoreExt
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: console.log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Conrad Irwin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lspace
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Allows you to log to the console.
|
28
|
+
email: conrad.irwin@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENSE.MIT
|
34
|
+
- README.md
|
35
|
+
- console.log.gemspec
|
36
|
+
- lib/console.log.rb
|
37
|
+
- lib/console.log/console.rb
|
38
|
+
- lib/console.log/core_ext.rb
|
39
|
+
- lib/console.log/middleware.rb
|
40
|
+
- lib/console.log/railtie.rb
|
41
|
+
homepage: http://github.com/ConradIrwin/console.log
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.2.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Port of console.log to ruby
|
65
|
+
test_files: []
|
66
|
+
has_rdoc:
|