easy_log4r 0.0.5 → 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/.rvmrc +48 -0
- data/README.rdoc +18 -3
- data/VERSION +1 -1
- data/easy_log4r.gemspec +7 -3
- data/lib/easy_log4r.rb +8 -0
- data/lib/easy_log4r/configurator.rb +16 -0
- data/lib/easy_log4r/logger.rb +19 -2
- data/lib/easy_log4r/outputter.rb +25 -0
- data/lib/easy_log4r/yamlconfigurator.rb +16 -0
- metadata +8 -4
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@easy_log4r"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.15.8 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/README.rdoc
CHANGED
@@ -2,7 +2,12 @@
|
|
2
2
|
|
3
3
|
easy-log4r is a quick and simple way to start using Log4r fast. It quickly and easily creates a default logger, as well as class and instance functions that can be used to access it. In addition, it also provides a simple way to disable logging, for whatever reason, without needing to actually remove or comment out the logging code you, hopefully, peppered through your code.
|
4
4
|
|
5
|
-
To get started simply
|
5
|
+
To get started simply put the following into your class and you're good to go!
|
6
|
+
|
7
|
+
require 'easy-log4r'
|
8
|
+
include EasyLog4r::EasyLogger
|
9
|
+
|
10
|
+
This gives you two default outputs, one to stdout for all levels of logging, and one to stderr for the error and fatal levels of logging.
|
6
11
|
|
7
12
|
To disable logging you can `include EasyLog4r::NullLogger`. You don't need to remove the EasyLogger you include to start logging, but you can if you want to.
|
8
13
|
|
@@ -10,9 +15,19 @@ The default logger is created using the base class's name, so if you want to cus
|
|
10
15
|
|
11
16
|
That's it! Quick, simple, easy logging using log4r.
|
12
17
|
|
13
|
-
==
|
18
|
+
== New Features
|
19
|
+
|
20
|
+
=== 0.1.0
|
21
|
+
|
22
|
+
You can now customize what outputters are used with easy_log4r! *Excitement!*
|
23
|
+
|
24
|
+
To do so, you must:
|
25
|
+
|
26
|
+
1. Use whichever method of configuration you prefer, xml or yaml, and you add a `default` attribute to the given outputter.
|
27
|
+
2. Include `require 'easy_log4r'` before you parse the configuration file. (This is so the monkey patches to Log4r's base classes can take effect)
|
28
|
+
3. Parse the configuration file! (You're done!)
|
14
29
|
|
15
|
-
|
30
|
+
If you have no clue how to use a configuration file to edit Log4r, head over to https://github.com/Valarissa/easy_log4r/wiki/Log4r-Yaml-Configuration
|
16
31
|
|
17
32
|
== Contributing to easy-log4r
|
18
33
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/easy_log4r.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "easy_log4r"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Lauren Voswinkel"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-09-20"
|
13
13
|
s.description = "Quick, simple, easy logging with log4r that can easily be toggled"
|
14
14
|
s.email = "lvoswink@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
+
".rvmrc",
|
21
22
|
"Gemfile",
|
22
23
|
"Gemfile.lock",
|
23
24
|
"LICENSE.txt",
|
@@ -26,9 +27,12 @@ Gem::Specification.new do |s|
|
|
26
27
|
"VERSION",
|
27
28
|
"easy_log4r.gemspec",
|
28
29
|
"lib/easy_log4r.rb",
|
30
|
+
"lib/easy_log4r/configurator.rb",
|
29
31
|
"lib/easy_log4r/easy_logger.rb",
|
30
32
|
"lib/easy_log4r/logger.rb",
|
31
33
|
"lib/easy_log4r/null_logger.rb",
|
34
|
+
"lib/easy_log4r/outputter.rb",
|
35
|
+
"lib/easy_log4r/yamlconfigurator.rb",
|
32
36
|
"test/helper.rb",
|
33
37
|
"test/test_easy_logger.rb",
|
34
38
|
"test/test_logger.rb",
|
@@ -37,7 +41,7 @@ Gem::Specification.new do |s|
|
|
37
41
|
s.homepage = "http://github.com/valarissa/easy_log4r"
|
38
42
|
s.licenses = ["MIT"]
|
39
43
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = "1.8.
|
44
|
+
s.rubygems_version = "1.8.23"
|
41
45
|
s.summary = "Easy logging using Log4r"
|
42
46
|
|
43
47
|
if s.respond_to? :specification_version then
|
data/lib/easy_log4r.rb
CHANGED
@@ -10,4 +10,12 @@ module EasyLog4r
|
|
10
10
|
require 'easy_log4r/logger'
|
11
11
|
require 'easy_log4r/easy_logger'
|
12
12
|
require 'easy_log4r/null_logger'
|
13
|
+
|
14
|
+
require 'log4r'
|
15
|
+
require 'log4r/configurator'
|
16
|
+
require 'log4r/yamlconfigurator'
|
17
|
+
|
18
|
+
require 'easy_log4r/outputter'
|
19
|
+
require 'easy_log4r/configurator'
|
20
|
+
require 'easy_log4r/yamlconfigurator'
|
13
21
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
##
|
2
|
+
# Extension of base Log4r::Configurator to enable decoding of a `default`
|
3
|
+
# attribute in the XML definition.
|
4
|
+
#
|
5
|
+
class Log4r::Configurator
|
6
|
+
class << self
|
7
|
+
alias :orig_decode_outputter :decode_outputter
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Decodes an outputter as normal, but also sets @default if it was defined in the given configuration file.
|
12
|
+
def self.decode_outputter(e)
|
13
|
+
orig_decode_outputter(e)
|
14
|
+
Log4r::Outputter[e.value_of('name')].default = !!e.value_of('default')
|
15
|
+
end
|
16
|
+
end
|
data/lib/easy_log4r/logger.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
#
|
4
4
|
class EasyLog4r::Logger
|
5
5
|
require 'log4r'
|
6
|
+
|
6
7
|
include Log4r
|
7
8
|
|
8
9
|
##
|
@@ -30,9 +31,11 @@ class EasyLog4r::Logger
|
|
30
31
|
# Those outputters are a Log4r::StdoutOutputter and a Log4r::StderrOutputter, both of which have a default Log4r::Formatter
|
31
32
|
def self.default_outputters
|
32
33
|
return @outputters if @outputters
|
34
|
+
|
33
35
|
@outputters = []
|
34
|
-
@outputters <<
|
35
|
-
@outputters <<
|
36
|
+
@outputters << configured_default_outputters
|
37
|
+
@outputters << standard_outputters if @outputters.empty?
|
38
|
+
@outputters.flatten!
|
36
39
|
|
37
40
|
return @outputters
|
38
41
|
end
|
@@ -47,6 +50,20 @@ class EasyLog4r::Logger
|
|
47
50
|
return out
|
48
51
|
end
|
49
52
|
|
53
|
+
##
|
54
|
+
# Gathers all Log4r::Outputters defined in the user defined configuration file.
|
55
|
+
def self.configured_default_outputters
|
56
|
+
Log4r::Outputter.default_outputters
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Defines two standard outputters, one which prints to stdout at all levels, and one which prints to stderr for error and fatal levels.
|
61
|
+
def self.standard_outputters
|
62
|
+
@outputters << default_outputter('formatted_stdout', StdoutOutputter)
|
63
|
+
@outputters << default_outputter('formatted_stderr', StderrOutputter)
|
64
|
+
Log4r::Outputter['formatted_stderr'].level = :error
|
65
|
+
end
|
66
|
+
|
50
67
|
##
|
51
68
|
# Creates or returns the default formatter.
|
52
69
|
#
|
@@ -0,0 +1,25 @@
|
|
1
|
+
##
|
2
|
+
# Extension of base Log4r::Outputter class to add @default as an attribute
|
3
|
+
# and a class-level method to retrieve all outputters that have that attribute
|
4
|
+
# set.
|
5
|
+
#
|
6
|
+
class Log4r::Outputter
|
7
|
+
attr_accessor :default
|
8
|
+
|
9
|
+
##
|
10
|
+
# Gathers all outputters that have @default set
|
11
|
+
def self.default_outputters
|
12
|
+
defaults = []
|
13
|
+
each_outputter do |outputter|
|
14
|
+
defaults << outputter if outputter.default?
|
15
|
+
end
|
16
|
+
|
17
|
+
return defaults
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Returns whether or not @default has been set
|
22
|
+
def default?
|
23
|
+
!!@default
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
##
|
2
|
+
# Extension of base Log4r::YamlConfigurator to enable decoding of a `default`
|
3
|
+
# attribute in the Yaml definition.
|
4
|
+
#
|
5
|
+
class Log4r::YamlConfigurator
|
6
|
+
class << self
|
7
|
+
alias :orig_decode_outputter :decode_outputter
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Decodes an outputter as normal, but also sets @default if it was defined in the given configuration file.
|
12
|
+
def self.decode_outputter( op )
|
13
|
+
orig_decode_outputter(op)
|
14
|
+
Log4r::Outputter[op['name']].default = !!op['default']
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_log4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: log4r
|
@@ -116,6 +116,7 @@ extra_rdoc_files:
|
|
116
116
|
- README.rdoc
|
117
117
|
files:
|
118
118
|
- .document
|
119
|
+
- .rvmrc
|
119
120
|
- Gemfile
|
120
121
|
- Gemfile.lock
|
121
122
|
- LICENSE.txt
|
@@ -124,9 +125,12 @@ files:
|
|
124
125
|
- VERSION
|
125
126
|
- easy_log4r.gemspec
|
126
127
|
- lib/easy_log4r.rb
|
128
|
+
- lib/easy_log4r/configurator.rb
|
127
129
|
- lib/easy_log4r/easy_logger.rb
|
128
130
|
- lib/easy_log4r/logger.rb
|
129
131
|
- lib/easy_log4r/null_logger.rb
|
132
|
+
- lib/easy_log4r/outputter.rb
|
133
|
+
- lib/easy_log4r/yamlconfigurator.rb
|
130
134
|
- test/helper.rb
|
131
135
|
- test/test_easy_logger.rb
|
132
136
|
- test/test_logger.rb
|
@@ -146,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
150
|
version: '0'
|
147
151
|
segments:
|
148
152
|
- 0
|
149
|
-
hash:
|
153
|
+
hash: -2590392929587300091
|
150
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
155
|
none: false
|
152
156
|
requirements:
|
@@ -155,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
159
|
version: '0'
|
156
160
|
requirements: []
|
157
161
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.8.
|
162
|
+
rubygems_version: 1.8.23
|
159
163
|
signing_key:
|
160
164
|
specification_version: 3
|
161
165
|
summary: Easy logging using Log4r
|