filter_log 1.0.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 +4 -0
- data/.rvmrc +1 -0
- data/DEVELOPER_README.md +23 -0
- data/Gemfile +4 -0
- data/README.md +62 -0
- data/Rakefile +1 -0
- data/filter_log.gemspec +18 -0
- data/lib/filter_log.rb +42 -0
- metadata +69 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3-p392@filter_log --create
|
data/DEVELOPER_README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# FilterLog
|
2
|
+
|
3
|
+
This is a README for working on FilterLog
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
|
7
|
+
```
|
8
|
+
gem build filter_log.gemspec
|
9
|
+
gem install ./filter_log-1.0.0.gem
|
10
|
+
```
|
11
|
+
|
12
|
+
## Running
|
13
|
+
|
14
|
+
Get into `irb`.
|
15
|
+
|
16
|
+
Run `require 'filter_log'`.
|
17
|
+
|
18
|
+
Now you can access the FilterLog object.
|
19
|
+
|
20
|
+
## All together now
|
21
|
+
|
22
|
+
`gem build filter_log.gemspec; gem install filter_log-1.0.0.gem; irb`
|
23
|
+
`require 'filter_log'`
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# FilterLog
|
2
|
+
|
3
|
+
FilterLog is a simple log that allows you to filter on which log messages get displayed by using tags.
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
FilterLog uses the [colored](https://github.com/defunkt/colored) gem to color output.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
### `.debug` and `.error`
|
12
|
+
|
13
|
+
FilterLog provides two functions for showing output, both of which render using `puts`.
|
14
|
+
|
15
|
+
These functions are `.debug` and `.error`.
|
16
|
+
|
17
|
+
`.debug` will render a string out like so:
|
18
|
+
|
19
|
+

|
20
|
+
|
21
|
+
`.error` will render a string out like so:
|
22
|
+
|
23
|
+

|
24
|
+
|
25
|
+
### Using tags
|
26
|
+
|
27
|
+
You can pass tags in to your log calls that the FilterLog class will use to determine whether or not to show a given log message.
|
28
|
+
|
29
|
+
By default, no tags are enabled. This means that the following call will render nothing:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
FilterLog.debug("Jordan rules", :my_tag)
|
33
|
+
```
|
34
|
+
|
35
|
+
To enable a tag, you can use:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
FilterLog.enableTags(:my_tag, :my_other_tag)
|
39
|
+
```
|
40
|
+
|
41
|
+
To disable a tag you can use:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
FilterLog.disableTags(:my_tag, :my_other_tag)
|
45
|
+
```
|
46
|
+
|
47
|
+
The purpose of using tagging is so you can reduce the amount of crap you see in your logs.
|
48
|
+
|
49
|
+
You can add as many tags as you want to a given log statement, so the following also works:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
FilterLog.debug("Jordan rules", :my_tag, :hedonism, :other_tag, :something_else)
|
53
|
+
```
|
54
|
+
|
55
|
+
Tags can be anything, so if you want to see logs only for a given object, you can do the following:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
jordan = Object.new
|
59
|
+
FilterLog.enableTags(jordan)
|
60
|
+
FilterLog.debug("I am a log", jordan)
|
61
|
+
```
|
62
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/filter_log.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "filter_log"
|
6
|
+
s.version = "1.0.0"
|
7
|
+
s.authors = ["Jordan Maguire"]
|
8
|
+
s.email = ["jmaguire@thefrontiergroup.com.au"]
|
9
|
+
s.homepage = "https://github.com/jordanmaguire/filter_log"
|
10
|
+
s.summary = "A filterable log for Ruby"
|
11
|
+
s.description = "Specify which types of log entry you want to see logged"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_dependency 'colored'
|
18
|
+
end
|
data/lib/filter_log.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'colored'
|
2
|
+
|
3
|
+
class FilterLog
|
4
|
+
|
5
|
+
def self.debug(message, *tags)
|
6
|
+
if tagsShouldOutput(tags)
|
7
|
+
output("Debug: ".cyan + message.white)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.error(message, *tags)
|
12
|
+
if tagsShouldOutput(tags)
|
13
|
+
output("Error: ".red + message.white)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.disableTags(*tags)
|
18
|
+
return enabledTags if tags.nil? || tags.empty?
|
19
|
+
tags.each { |tag| enabledTags.delete(tag) }
|
20
|
+
enabledTags
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.enabledTags
|
24
|
+
@enabledTags ||= []
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.enableTags(*tags)
|
28
|
+
enabledTags.concat(tags).uniq!
|
29
|
+
enabledTags
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.output(message)
|
35
|
+
puts("#{message}\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.tagsShouldOutput(tags)
|
39
|
+
tags.nil? || tags.empty? || tags.any? { |x| enabledTags.include?(x) }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filter_log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jordan Maguire
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colored
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Specify which types of log entry you want to see logged
|
31
|
+
email:
|
32
|
+
- jmaguire@thefrontiergroup.com.au
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rvmrc
|
39
|
+
- DEVELOPER_README.md
|
40
|
+
- Gemfile
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- filter_log.gemspec
|
44
|
+
- lib/filter_log.rb
|
45
|
+
homepage: https://github.com/jordanmaguire/filter_log
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.25
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: A filterable log for Ruby
|
69
|
+
test_files: []
|