treefell 0.2.3 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +75 -2
- data/examples/example_1.png +0 -0
- data/examples/example_2.png +0 -0
- data/examples/example_3.png +0 -0
- data/examples/program.rb +12 -0
- data/lib/treefell/debug_logger.rb +9 -0
- data/lib/treefell/filters/env_filter.rb +3 -3
- data/lib/treefell/version.rb +1 -1
- data/lib/treefell.rb +22 -8
- data/treefell.gemspec +1 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebeb16ac49693f30536f49f3bf7de672c83d8ebd
|
4
|
+
data.tar.gz: fab978b8ea55f12886bef500dc405bdaec51e6dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd51cc55d02e9f3dc966ce7990fca5fe8de0014209a9dd91fc61311b9353a7d9eef3b982a22b4090d3533aa408c66ef3c21a3151b41c2f29fe1ce93ecd7e880d
|
7
|
+
data.tar.gz: 479759a67145d4cbd0c46f354b1d92aaa7a9ef2bda799ddbf433f35962a5ce45ae72bc2482dcd18c0623443b7153060cc8c0220523621cacc8908837b371f932
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Treefell [](https://travis-ci.org/zdennis/treefell)
|
2
2
|
|
3
|
-
|
3
|
+
> If a tree falls in a forest and no one is around to hear it, does it make a sound?
|
4
|
+
|
5
|
+
Treefell is a minimalist debug-logging library for ruby. It uses the DEBUG environment variable to determine which debug messages are logged and which are suppressed.
|
6
|
+
|
7
|
+
This project was inspired by visionmedia's [debug](https://github.com/visionmedia/debug) library for nodejs.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -18,7 +22,76 @@ Or install it yourself as:
|
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
25
|
+
Take the ruby program:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
#!/usr/bin/env ruby
|
29
|
+
|
30
|
+
require 'treefell'
|
31
|
+
|
32
|
+
foo_debug = Treefell['foo']
|
33
|
+
foo_debug.puts 'too funky in here'
|
34
|
+
|
35
|
+
bar_debug = Treefell['bar']
|
36
|
+
bar_debug.puts 'you got that right'
|
37
|
+
|
38
|
+
baz_debug = Treefell['baz']
|
39
|
+
baz_debug.puts 'say it again'
|
40
|
+
```
|
41
|
+
|
42
|
+
Each call to `Treefell['...']` instantiates a `DebugLogger` for the provided
|
43
|
+
namespace (e.g. foo, bar, baz).
|
44
|
+
|
45
|
+
By default no debug log statements are displayed:
|
46
|
+
|
47
|
+
```
|
48
|
+
> ruby program.rb
|
49
|
+
```
|
50
|
+
|
51
|
+
### Displaying all messages
|
52
|
+
|
53
|
+
You can tell it to display all messages with the wildcard `*`:
|
54
|
+
|
55
|
+

|
56
|
+
|
57
|
+
### Displaying messages from a particular namespace
|
58
|
+
|
59
|
+
Here's how to display messages for one specific debugging namespace:
|
60
|
+
|
61
|
+

|
62
|
+
|
63
|
+
### Displaying messages for multiple namespaces
|
64
|
+
|
65
|
+
To display messages from multiple namespaces use a comma-separated list of
|
66
|
+
namespaces:
|
67
|
+
|
68
|
+

|
69
|
+
|
70
|
+
### Colored output
|
71
|
+
|
72
|
+
Every namespace gets a color associated with it to aide in the visual parsing
|
73
|
+
of the output. Also `DebugLogger`(s) are cached per namespace so regardless
|
74
|
+
of when you refer to the namespace it will always have the same color
|
75
|
+
associated with it.
|
76
|
+
|
77
|
+
E.g.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
foo_debug = Treefell['foo']
|
81
|
+
other_foo_debug = Treefell['foo']
|
82
|
+
|
83
|
+
foo_debug.eql?(other_foo_debug) # => true
|
84
|
+
```
|
85
|
+
|
86
|
+
#### Sending to IO other than STDOUT
|
87
|
+
|
88
|
+
By default all messages are written to `STDOUT`. You can change this by
|
89
|
+
instantiating a debug logger using the `debug` method, e.g.:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
foo_debug = Treefell.debug('foo', io: some_io)
|
93
|
+
foo_debug.puts 'Get up offa that thing, and dance till you feel better'
|
94
|
+
```
|
22
95
|
|
23
96
|
## Contributing
|
24
97
|
|
Binary file
|
Binary file
|
Binary file
|
data/examples/program.rb
ADDED
@@ -12,6 +12,15 @@ module Treefell
|
|
12
12
|
@filter = filter || DEFAULT_FILTER_PROC
|
13
13
|
end
|
14
14
|
|
15
|
+
def [](sub_namespace)
|
16
|
+
@debug_loggers ||= {}
|
17
|
+
@debug_loggers[sub_namespace] ||= DebugLogger.new(
|
18
|
+
namespace: sub_namespace,
|
19
|
+
io: self,
|
20
|
+
filter: DEFAULT_FILTER_PROC
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
15
24
|
def puts(message)
|
16
25
|
if @filter.call(namespace, message)
|
17
26
|
formatted_namespace = if namespace
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Treefell
|
2
2
|
module Filters
|
3
3
|
class EnvFilter
|
4
|
-
|
5
|
-
|
4
|
+
NAMESPACE_ENV_VAR_KEY = 'DEBUG'
|
5
|
+
NAMESPACE_ENV_VAR_LOOKUP = -> { ENV[NAMESPACE_ENV_VAR_KEY] }
|
6
6
|
WILDCARD = '*'
|
7
7
|
|
8
|
-
def initialize(value:
|
8
|
+
def initialize(value: NAMESPACE_ENV_VAR_LOOKUP)
|
9
9
|
@value_proc = value
|
10
10
|
end
|
11
11
|
|
data/lib/treefell/version.rb
CHANGED
data/lib/treefell.rb
CHANGED
@@ -5,18 +5,28 @@ require 'treefell/debug_logger'
|
|
5
5
|
require 'treefell/filters/env_filter'
|
6
6
|
|
7
7
|
module Treefell
|
8
|
-
|
8
|
+
NAMESPACE_ENV_VAR_LOOKUP = -> { ENV[Treefell.namespace_env_var] }
|
9
9
|
|
10
|
-
def self.
|
11
|
-
@
|
10
|
+
def self.namespace_env_var=(namespace_env_var)
|
11
|
+
@namespace_env_var = namespace_env_var
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.
|
15
|
-
@
|
14
|
+
def self.namespace_env_var
|
15
|
+
@namespace_env_var || Filters::EnvFilter::NAMESPACE_ENV_VAR_KEY
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.debug(namespace=nil, io:
|
19
|
-
|
18
|
+
def self.debug(namespace=nil, io: nil, filter: nil)
|
19
|
+
io ||= begin
|
20
|
+
treefell_out = ENV['TREEFELL_OUT']
|
21
|
+
if treefell_out
|
22
|
+
@treefell_out_io ||= File.open(treefell_out, 'w+').tap do |io|
|
23
|
+
io.sync = true
|
24
|
+
end
|
25
|
+
else
|
26
|
+
$stdout
|
27
|
+
end
|
28
|
+
end
|
29
|
+
filter ||= Filters::EnvFilter.new(value: NAMESPACE_ENV_VAR_LOOKUP)
|
20
30
|
@debug_loggers ||= {}
|
21
31
|
@debug_loggers[namespace] ||= DebugLogger.new(
|
22
32
|
namespace: namespace,
|
@@ -26,8 +36,12 @@ module Treefell
|
|
26
36
|
end
|
27
37
|
|
28
38
|
def self.reset
|
39
|
+
if @treefell_out_io
|
40
|
+
@treefell_out_io.close unless @treefell_out_io.closed?
|
41
|
+
@treefell_out_io = nil
|
42
|
+
end
|
29
43
|
@debug_loggers.clear if @debug_loggers
|
30
|
-
@
|
44
|
+
@namespace_env_var = nil
|
31
45
|
end
|
32
46
|
|
33
47
|
def self.[](namespace)
|
data/treefell.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
+
s.add_dependency "ansi_string", "~> 0.1"
|
23
24
|
s.add_dependency "term-ansicolor", "~> 1.3"
|
24
25
|
s.add_development_dependency 'rspec', '~> 3.4.0', '>= 3.4'
|
25
26
|
s.add_development_dependency 'climate_control', '~> 0.0.3'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: treefell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ansi_string
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: term-ansicolor
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,10 @@ extra_rdoc_files: []
|
|
66
80
|
files:
|
67
81
|
- README.md
|
68
82
|
- Rakefile
|
83
|
+
- examples/example_1.png
|
84
|
+
- examples/example_2.png
|
85
|
+
- examples/example_3.png
|
86
|
+
- examples/program.rb
|
69
87
|
- lib/tasks/gem.rake
|
70
88
|
- lib/treefell.rb
|
71
89
|
- lib/treefell/color.rb
|
@@ -93,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
111
|
version: '0'
|
94
112
|
requirements: []
|
95
113
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.5.1
|
97
115
|
signing_key:
|
98
116
|
specification_version: 4
|
99
117
|
summary: Treefell is a simple debug-logging library for ruby
|