logsly 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -2
- data/README.md +1 -1
- data/lib/logsly.rb +53 -1
- data/lib/logsly/colors.rb +4 -4
- data/lib/logsly/version.rb +1 -1
- data/logsly.gemspec +5 -4
- data/test/helper.rb +2 -0
- data/test/support/factory.rb +6 -0
- data/test/unit/base_output_tests.rb +50 -49
- data/test/unit/colors_tests.rb +49 -48
- data/test/unit/file_output_tests.rb +19 -17
- data/test/unit/logsly_tests.rb +228 -0
- data/test/unit/stdout_output_tests.rb +7 -5
- data/test/unit/syslog_output_tests.rb +26 -24
- metadata +64 -87
- data/lib/logsly/settings.rb +0 -45
- data/test/unit/logger_tests.rb +0 -123
- data/test/unit/settings_tests.rb +0 -98
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2dfa76f82b146db11ebe7e52e8ac9bb51f0fc9c8
|
4
|
+
data.tar.gz: 9dbc80bdfe08dce4f6acacf50f29aca0b90965ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1629d93cc3f4b0f8979ac796ef219ccf05aecc85750829029f20c1f5c48d8dd05117b65e27112ca7509530152dbec2a01ad04b068b127e7a41ce513667bb16c8
|
7
|
+
data.tar.gz: 0abc0262c174e4e12a31c8a81f659888379ce5ec9538bbbbffab0c2d4efd1b0b414c3b27befa7a15a7be6c9dbdfbb02075bff6d4cdeac44858511c22272d2518
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ logger = MyLogger.new(:outputs => ['my_stdout'])
|
|
19
19
|
logger.info "whatever"
|
20
20
|
|
21
21
|
# build another logger and use it
|
22
|
-
bg_logger = MyLogger.new('bg', :level => 'debug', :outputs => ['
|
22
|
+
bg_logger = MyLogger.new('bg', :level => 'debug', :outputs => ['my_stdout'])
|
23
23
|
bg_logger.debug "something"
|
24
24
|
```
|
25
25
|
|
data/lib/logsly.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'ns-options'
|
2
2
|
require 'logging'
|
3
3
|
require 'logsly/version'
|
4
|
-
require 'logsly/
|
4
|
+
require 'logsly/colors'
|
5
|
+
require 'logsly/base_output'
|
5
6
|
|
6
7
|
module Logsly
|
7
8
|
|
@@ -12,6 +13,43 @@ module Logsly
|
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
module Settings
|
17
|
+
include NsOptions::Proxy
|
18
|
+
|
19
|
+
option :colors, ::Hash, :default => ::Hash.new(NullColors.new)
|
20
|
+
option :outputs, ::Hash, :default => ::Hash.new(NullOutput.new)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.reset
|
24
|
+
Settings.reset
|
25
|
+
Logging.reset
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.colors(name, &block)
|
29
|
+
require 'logsly/colors'
|
30
|
+
Settings.colors[name.to_s] = Colors.new(name, &block) if !block.nil?
|
31
|
+
Settings.colors[name.to_s]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.stdout(name, &block)
|
35
|
+
require 'logsly/stdout_output'
|
36
|
+
Settings.outputs[name.to_s] = StdoutOutput.new(&block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.file(name, &block)
|
40
|
+
require 'logsly/file_output'
|
41
|
+
Settings.outputs[name.to_s] = FileOutput.new(&block)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.syslog(name, &block)
|
45
|
+
require 'logsly/syslog_output'
|
46
|
+
Settings.outputs[name.to_s] = SyslogOutput.new(&block)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.outputs(name)
|
50
|
+
Settings.outputs[name.to_s]
|
51
|
+
end
|
52
|
+
|
15
53
|
module LoggerMethods
|
16
54
|
|
17
55
|
def initialize(log_type, opts_hash=nil)
|
@@ -30,6 +68,16 @@ module Logsly
|
|
30
68
|
end
|
31
69
|
end
|
32
70
|
|
71
|
+
def mdc(key, value)
|
72
|
+
Logging.mdc[key] = value
|
73
|
+
end
|
74
|
+
|
75
|
+
def file_path
|
76
|
+
@file_path ||= if (appender = get_file_appender)
|
77
|
+
appender.name if appender.respond_to?(:name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
33
81
|
# delegate all calls to the @logger
|
34
82
|
|
35
83
|
def method_missing(method, *args, &block)
|
@@ -65,6 +113,10 @@ module Logsly
|
|
65
113
|
end
|
66
114
|
end
|
67
115
|
|
116
|
+
def get_file_appender
|
117
|
+
@logger.appenders.detect{ |a| a.kind_of?(Logging::Appenders::File) }
|
118
|
+
end
|
119
|
+
|
68
120
|
end
|
69
121
|
|
70
122
|
end
|
data/lib/logsly/colors.rb
CHANGED
@@ -8,10 +8,6 @@ require 'ns-options'
|
|
8
8
|
|
9
9
|
module Logsly
|
10
10
|
|
11
|
-
class NullColors < OpenStruct
|
12
|
-
def to_scheme(*args); nil; end
|
13
|
-
end
|
14
|
-
|
15
11
|
class Colors
|
16
12
|
|
17
13
|
attr_reader :name, :build
|
@@ -28,6 +24,10 @@ module Logsly
|
|
28
24
|
|
29
25
|
end
|
30
26
|
|
27
|
+
class NullColors < OpenStruct
|
28
|
+
def to_scheme(*args); nil; end
|
29
|
+
end
|
30
|
+
|
31
31
|
class ColorsData
|
32
32
|
include NsOptions::Proxy
|
33
33
|
|
data/lib/logsly/version.rb
CHANGED
data/logsly.gemspec
CHANGED
@@ -11,13 +11,14 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.description = %q{Create custom loggers.}
|
12
12
|
gem.summary = %q{Create custom loggers.}
|
13
13
|
gem.homepage = "http://github.com/redding/logsly"
|
14
|
+
gem.license = 'MIT'
|
14
15
|
|
15
|
-
gem.files = `git ls-files`.split(
|
16
|
-
gem.
|
17
|
-
gem.
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ["lib"]
|
19
20
|
|
20
|
-
gem.add_development_dependency("assert", ["~> 2.
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.15"])
|
21
22
|
|
22
23
|
gem.add_dependency("ns-options", ["~> 1.1"])
|
23
24
|
gem.add_dependency("logging", ["~> 1.7"])
|
data/test/helper.rb
CHANGED
@@ -1,59 +1,17 @@
|
|
1
1
|
require 'assert'
|
2
|
-
require 'logging'
|
3
|
-
require 'logsly/settings'
|
4
2
|
require 'logsly/base_output'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
class DataTests < Assert::Context
|
9
|
-
desc "the BaseOutputData handler"
|
10
|
-
setup do
|
11
|
-
Logsly.colors('a_color_scheme') do
|
12
|
-
debug :white
|
13
|
-
end
|
14
|
-
@arg = '%d : %m\n'
|
15
|
-
@lay = Logsly::BaseOutputData.new(@arg) do |*args|
|
16
|
-
pattern args.first
|
17
|
-
colors 'a_color_scheme'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
subject { @lay }
|
21
|
-
|
22
|
-
should have_readers :pattern, :colors
|
23
|
-
|
24
|
-
should "know its defaults" do
|
25
|
-
lay = Logsly::BaseOutputData.new {}
|
26
|
-
assert_equal '%m\n', lay.pattern
|
27
|
-
assert_nil lay.colors
|
28
|
-
end
|
29
|
-
|
30
|
-
should "instance exec its build with args" do
|
31
|
-
assert_equal '%d : %m\n', subject.pattern
|
32
|
-
assert_equal 'a_color_scheme', subject.colors
|
33
|
-
end
|
34
|
-
|
35
|
-
should "know its layout pattern opts hash" do
|
36
|
-
expected = {
|
37
|
-
:pattern => subject.pattern,
|
38
|
-
:color_scheme => "#{subject.colors}-#{@arg.object_id}"
|
39
|
-
}
|
40
|
-
assert_equal expected, subject.to_pattern_opts
|
41
|
-
|
42
|
-
out = Logsly::BaseOutputData.new do
|
43
|
-
pattern '%m\n'
|
44
|
-
end
|
45
|
-
out_expected = {:pattern => out.pattern}
|
46
|
-
assert_equal out_expected, out.to_pattern_opts
|
47
|
-
end
|
4
|
+
require 'logging'
|
5
|
+
require 'logsly'
|
48
6
|
|
49
|
-
|
7
|
+
class Logsly::BaseOutput
|
50
8
|
|
51
|
-
class
|
52
|
-
desc "
|
9
|
+
class UnitTests < Assert::Context
|
10
|
+
desc "Logsly::BaseOutput"
|
53
11
|
setup do
|
54
12
|
@out = Logsly::BaseOutput.new {}
|
55
13
|
end
|
56
|
-
subject
|
14
|
+
subject{ @out }
|
57
15
|
|
58
16
|
should have_reader :build
|
59
17
|
should have_imeths :to_layout, :to_appender
|
@@ -73,7 +31,7 @@ class Logsly::BaseOutput
|
|
73
31
|
|
74
32
|
end
|
75
33
|
|
76
|
-
class BuildTests <
|
34
|
+
class BuildTests < UnitTests
|
77
35
|
desc "given a build"
|
78
36
|
setup do
|
79
37
|
Logsly.colors('a_color_scheme') do
|
@@ -96,5 +54,48 @@ class Logsly::BaseOutput
|
|
96
54
|
|
97
55
|
end
|
98
56
|
|
57
|
+
class BaseOutputDataTests < Assert::Context
|
58
|
+
desc "BaseOutputData"
|
59
|
+
setup do
|
60
|
+
Logsly.colors('a_color_scheme') do
|
61
|
+
debug :white
|
62
|
+
end
|
63
|
+
@arg = '%d : %m\n'
|
64
|
+
@lay = Logsly::BaseOutputData.new(@arg) do |*args|
|
65
|
+
pattern args.first
|
66
|
+
colors 'a_color_scheme'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
subject{ @lay }
|
70
|
+
|
71
|
+
should have_readers :pattern, :colors
|
72
|
+
|
73
|
+
should "know its defaults" do
|
74
|
+
lay = Logsly::BaseOutputData.new {}
|
75
|
+
assert_equal '%m\n', lay.pattern
|
76
|
+
assert_nil lay.colors
|
77
|
+
end
|
78
|
+
|
79
|
+
should "instance exec its build with args" do
|
80
|
+
assert_equal '%d : %m\n', subject.pattern
|
81
|
+
assert_equal 'a_color_scheme', subject.colors
|
82
|
+
end
|
83
|
+
|
84
|
+
should "know its layout pattern opts hash" do
|
85
|
+
expected = {
|
86
|
+
:pattern => subject.pattern,
|
87
|
+
:color_scheme => "#{subject.colors}-#{@arg.object_id}"
|
88
|
+
}
|
89
|
+
assert_equal expected, subject.to_pattern_opts
|
90
|
+
|
91
|
+
out = Logsly::BaseOutputData.new do
|
92
|
+
pattern '%m\n'
|
93
|
+
end
|
94
|
+
out_expected = {:pattern => out.pattern}
|
95
|
+
assert_equal out_expected, out.to_pattern_opts
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
99
100
|
end
|
100
101
|
|
data/test/unit/colors_tests.rb
CHANGED
@@ -1,17 +1,62 @@
|
|
1
1
|
require 'assert'
|
2
|
-
require 'logging'
|
3
2
|
require 'logsly/colors'
|
4
3
|
|
4
|
+
require 'logging'
|
5
|
+
|
5
6
|
class Logsly::Colors
|
6
7
|
|
7
|
-
class
|
8
|
-
desc "
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Logsly::Colors"
|
10
|
+
setup do
|
11
|
+
@colors = Logsly::Colors.new('test_colors') do |*args|
|
12
|
+
debug args.first
|
13
|
+
end
|
14
|
+
end
|
15
|
+
subject{ @colors }
|
16
|
+
|
17
|
+
should have_readers :name, :build
|
18
|
+
should have_imeths :to_scheme
|
19
|
+
|
20
|
+
should "know its name" do
|
21
|
+
assert_equal 'test_colors', subject.name
|
22
|
+
end
|
23
|
+
|
24
|
+
should "know its build" do
|
25
|
+
build_proc = Proc.new {}
|
26
|
+
out = Logsly::Colors.new 'test', &build_proc
|
27
|
+
|
28
|
+
assert_same build_proc, out.build
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class BuildTests < UnitTests
|
34
|
+
desc "given a build"
|
35
|
+
setup do
|
36
|
+
@colors = Logsly::Colors.new 'test' do |fatal_color|
|
37
|
+
fatal [fatal_color, :on_red]
|
38
|
+
date :blue
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should "build a unique Logging color scheme based on called args" do
|
43
|
+
arg = 'white'
|
44
|
+
scheme_name = subject.to_scheme(arg)
|
45
|
+
|
46
|
+
assert_equal "test-#{arg.object_id}", scheme_name
|
47
|
+
assert_kind_of Logging::ColorScheme, Logging.color_scheme(scheme_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class ColorsDataTests < Assert::Context
|
53
|
+
desc "ColorsData"
|
9
54
|
setup do
|
10
55
|
@data = Logsly::ColorsData.new('white') do |color|
|
11
56
|
debug color
|
12
57
|
end
|
13
58
|
end
|
14
|
-
subject
|
59
|
+
subject{ @data }
|
15
60
|
|
16
61
|
should have_imeths :to_scheme_opts
|
17
62
|
should have_imeths :debug, :info, :warn, :error, :fatal
|
@@ -64,49 +109,5 @@ class Logsly::Colors
|
|
64
109
|
|
65
110
|
end
|
66
111
|
|
67
|
-
class BaseTests < Assert::Context
|
68
|
-
desc "the Colors handler"
|
69
|
-
setup do
|
70
|
-
@colors = Logsly::Colors.new('test_colors') do |*args|
|
71
|
-
debug args.first
|
72
|
-
end
|
73
|
-
end
|
74
|
-
subject { @colors }
|
75
|
-
|
76
|
-
should have_readers :name, :build
|
77
|
-
should have_imeths :to_scheme
|
78
|
-
|
79
|
-
should "know its name" do
|
80
|
-
assert_equal 'test_colors', subject.name
|
81
|
-
end
|
82
|
-
|
83
|
-
should "know its build" do
|
84
|
-
build_proc = Proc.new {}
|
85
|
-
out = Logsly::Colors.new 'test', &build_proc
|
86
|
-
|
87
|
-
assert_same build_proc, out.build
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
class BuildTests < BaseTests
|
93
|
-
desc "given a build"
|
94
|
-
setup do
|
95
|
-
@colors = Logsly::Colors.new 'test' do |fatal_color|
|
96
|
-
fatal [fatal_color, :on_red]
|
97
|
-
date :blue
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
should "build a unique Logging color scheme based on called args" do
|
102
|
-
arg = 'white'
|
103
|
-
scheme_name = subject.to_scheme(arg)
|
104
|
-
|
105
|
-
assert_equal "test-#{arg.object_id}", scheme_name
|
106
|
-
assert_kind_of Logging::ColorScheme, Logging.color_scheme(scheme_name)
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
112
|
end
|
112
113
|
|
@@ -1,24 +1,14 @@
|
|
1
1
|
require 'assert'
|
2
|
-
require 'ostruct'
|
3
|
-
require 'logging'
|
4
|
-
require 'logsly/settings'
|
5
2
|
require 'logsly/file_output'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
desc "the FileOutputData handler"
|
11
|
-
setup do
|
12
|
-
@data = Logsly::FileOutputData.new {}
|
13
|
-
end
|
14
|
-
subject { @data }
|
15
|
-
|
16
|
-
should have_imeth :path
|
4
|
+
require 'logging'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'logsly'
|
17
7
|
|
18
|
-
|
8
|
+
class Logsly::FileOutput
|
19
9
|
|
20
|
-
class
|
21
|
-
desc "
|
10
|
+
class UnitTests < Assert::Context
|
11
|
+
desc "Logsly::FileOutput"
|
22
12
|
setup do
|
23
13
|
@logger = OpenStruct.new
|
24
14
|
@logger.debug_level = :white
|
@@ -36,7 +26,7 @@ class Logsly::FileOutput
|
|
36
26
|
colors 'a_color_scheme'
|
37
27
|
end
|
38
28
|
end
|
39
|
-
subject
|
29
|
+
subject{ @out }
|
40
30
|
|
41
31
|
should "be an output handler" do
|
42
32
|
assert_kind_of Logsly::BaseOutput, subject
|
@@ -51,6 +41,18 @@ class Logsly::FileOutput
|
|
51
41
|
assert_equal '%d : %m\n', appender.layout.pattern
|
52
42
|
assert_kind_of Logging::ColorScheme, appender.layout.color_scheme
|
53
43
|
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class FileOutputDataTests < Assert::Context
|
48
|
+
desc "FileOutputData"
|
49
|
+
setup do
|
50
|
+
@data = Logsly::FileOutputData.new {}
|
51
|
+
end
|
52
|
+
subject{ @data }
|
53
|
+
|
54
|
+
should have_imeth :path
|
55
|
+
|
54
56
|
end
|
55
57
|
|
56
58
|
end
|
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'logsly'
|
3
|
+
|
4
|
+
require 'logging'
|
5
|
+
require 'test/support/logger'
|
6
|
+
|
7
|
+
module Logsly
|
8
|
+
|
9
|
+
class UnitTests < Assert::Context
|
10
|
+
desc "Logsly"
|
11
|
+
setup do
|
12
|
+
Logsly.reset
|
13
|
+
end
|
14
|
+
subject{ Logsly }
|
15
|
+
|
16
|
+
should have_imeths :reset, :colors, :stdout, :file, :syslog, :outputs
|
17
|
+
|
18
|
+
should "return a NullColors obj when requesting a color scheme that isn't defined" do
|
19
|
+
assert_kind_of NullColors, Logsly.colors('not_defined_yet')
|
20
|
+
end
|
21
|
+
|
22
|
+
should "return a NullOutput obj when requesting an output that isn't defined" do
|
23
|
+
assert_kind_of NullOutput, Logsly.outputs('not_defined_yet')
|
24
|
+
end
|
25
|
+
|
26
|
+
should "add a named color scheme using the `colors` method" do
|
27
|
+
assert_kind_of NullColors, Logsly.colors('test_colors')
|
28
|
+
Logsly.colors('test_colors') {}
|
29
|
+
|
30
|
+
assert_kind_of Colors, Logsly.colors('test_colors')
|
31
|
+
end
|
32
|
+
|
33
|
+
should "add a named stdout output using the `stdout` method" do
|
34
|
+
assert_kind_of NullOutput, Logsly.outputs('test_stdout')
|
35
|
+
Logsly.stdout('test_stdout') {}
|
36
|
+
|
37
|
+
assert_not_nil Logsly.outputs('test_stdout')
|
38
|
+
assert_kind_of StdoutOutput, Logsly.outputs('test_stdout')
|
39
|
+
end
|
40
|
+
|
41
|
+
should "add a named file output using the `file` method" do
|
42
|
+
assert_kind_of NullOutput, Logsly.outputs('test_file')
|
43
|
+
Logsly.file('test_file') {}
|
44
|
+
|
45
|
+
assert_not_nil Logsly.outputs('test_file')
|
46
|
+
assert_kind_of FileOutput, Logsly.outputs('test_file')
|
47
|
+
end
|
48
|
+
|
49
|
+
should "add a named syslog output using the `syslog` method" do
|
50
|
+
assert_kind_of NullOutput, Logsly.outputs('test_syslog')
|
51
|
+
Logsly.syslog('test_syslog') {}
|
52
|
+
|
53
|
+
assert_not_nil Logsly.outputs('test_syslog')
|
54
|
+
assert_kind_of SyslogOutput, Logsly.outputs('test_syslog')
|
55
|
+
end
|
56
|
+
|
57
|
+
should "convert non-string setting names to string" do
|
58
|
+
Logsly.colors(:test_colors) {}
|
59
|
+
|
60
|
+
assert_not_nil Logsly.colors(:test_colors)
|
61
|
+
assert_kind_of Colors, Logsly.colors(:test_colors)
|
62
|
+
end
|
63
|
+
|
64
|
+
should "overwrite same-named colors settings" do
|
65
|
+
Logsly.colors('something') {}
|
66
|
+
orig = Logsly.colors('something')
|
67
|
+
Logsly.colors('something') {}
|
68
|
+
|
69
|
+
assert_not_same orig, Logsly.colors('something')
|
70
|
+
end
|
71
|
+
|
72
|
+
should "overwrite same-named outputs settings" do
|
73
|
+
Logsly.stdout('something') {}
|
74
|
+
assert_kind_of StdoutOutput, Logsly.outputs('something')
|
75
|
+
|
76
|
+
Logsly.file('something') {}
|
77
|
+
assert_kind_of FileOutput, Logsly.outputs('something')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
class ResetTests < UnitTests
|
83
|
+
desc "`reset` method"
|
84
|
+
setup do
|
85
|
+
Logsly.colors('test_colors') {}
|
86
|
+
Logsly.stdout('test_stdout') {}
|
87
|
+
end
|
88
|
+
|
89
|
+
should "reset the Settings" do
|
90
|
+
assert_kind_of Colors, Logsly.colors('test_colors')
|
91
|
+
assert_kind_of StdoutOutput, Logsly.outputs('test_stdout')
|
92
|
+
|
93
|
+
Logsly.reset
|
94
|
+
|
95
|
+
assert_kind_of NullColors, Logsly.colors('test_colors')
|
96
|
+
assert_kind_of NullOutput, Logsly.outputs('test_stdout')
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
class LoggerTests < UnitTests
|
102
|
+
desc "logger"
|
103
|
+
setup do
|
104
|
+
@logger = TestLogger.new(:testy_log_logger)
|
105
|
+
end
|
106
|
+
subject{ @logger }
|
107
|
+
|
108
|
+
should have_readers :log_type, :level, :outputs, :logger
|
109
|
+
should have_imeths :mdc, :file_path
|
110
|
+
|
111
|
+
should "know its log_type" do
|
112
|
+
assert_equal 'testy_log_logger', subject.log_type
|
113
|
+
end
|
114
|
+
|
115
|
+
should "know its default opt values" do
|
116
|
+
assert_equal 'info', subject.level
|
117
|
+
assert_equal [], subject.outputs
|
118
|
+
end
|
119
|
+
|
120
|
+
should "allow overridding the default opt values" do
|
121
|
+
log = TestLogger.new(:testy_debug_logger, :level => :debug, :outputs => [:stdout])
|
122
|
+
assert_equal 'debug', log.level
|
123
|
+
assert_equal [:stdout], log.outputs
|
124
|
+
end
|
125
|
+
|
126
|
+
should "create a Logging::Logger" do
|
127
|
+
assert_not_nil subject.logger
|
128
|
+
assert_kind_of Logging::Logger, subject.logger
|
129
|
+
end
|
130
|
+
|
131
|
+
should "create the Logging::Logger with a unique name" do
|
132
|
+
expected = "#{subject.class.name}-testy_log_logger-#{subject.object_id}"
|
133
|
+
assert_equal expected, subject.logger.name
|
134
|
+
end
|
135
|
+
|
136
|
+
should "set the logger's level" do
|
137
|
+
assert_equal Logging::LEVELS['info'], subject.logger.level
|
138
|
+
|
139
|
+
log = TestLogger.new('test', :level => :debug)
|
140
|
+
assert_equal Logging::LEVELS['debug'], log.logger.level
|
141
|
+
end
|
142
|
+
|
143
|
+
should "set mdc key/value pairs" do
|
144
|
+
key = Factory.string
|
145
|
+
assert_nil Logging.mdc[key]
|
146
|
+
|
147
|
+
value = Factory.string
|
148
|
+
subject.mdc(key, value)
|
149
|
+
assert_equal value, Logging.mdc[key]
|
150
|
+
end
|
151
|
+
|
152
|
+
should "not have a file path if no file appender is specified" do
|
153
|
+
assert_nil subject.file_path
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
class AppenderTests < UnitTests
|
159
|
+
setup do
|
160
|
+
Logsly.stdout 'my_stdout'
|
161
|
+
Logsly.file('my_file') do |logger|
|
162
|
+
path "log/development-#{logger.log_type}.log"
|
163
|
+
end
|
164
|
+
Logsly.file('my_other_file') do |logger|
|
165
|
+
path "log/other-#{logger.log_type}.log"
|
166
|
+
end
|
167
|
+
Logsly.syslog('my_syslog') do |logger|
|
168
|
+
identity "my_syslog_logger-#{logger.log_type}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
should "add a named stdout appender" do
|
173
|
+
log = TestLogger.new(:test, :outputs => 'my_stdout')
|
174
|
+
assert_includes_appender Logging::Appenders::Stdout, log
|
175
|
+
assert_nil log.file_path
|
176
|
+
end
|
177
|
+
|
178
|
+
should "add a named file appender" do
|
179
|
+
log = TestLogger.new(:test, :outputs => 'my_file')
|
180
|
+
filelog = extract_appender_from_logger(log, :file)
|
181
|
+
|
182
|
+
assert_includes_appender Logging::Appenders::File, log
|
183
|
+
assert_equal 'log/development-test.log', filelog.name
|
184
|
+
assert_equal 'log/development-test.log', log.file_path
|
185
|
+
end
|
186
|
+
|
187
|
+
should "add a named syslog appender" do
|
188
|
+
log = TestLogger.new(:test, :outputs => 'my_syslog')
|
189
|
+
assert_includes_appender Logging::Appenders::Syslog, log
|
190
|
+
assert_nil log.file_path
|
191
|
+
end
|
192
|
+
|
193
|
+
should "not add duplicate appenders" do
|
194
|
+
outputs = ['my_stdout', 'my_stdout', 'my_file', 'my_other_file']
|
195
|
+
log = TestLogger.new(:test, :outputs => outputs)
|
196
|
+
|
197
|
+
assert_equal 3, log.appenders.size
|
198
|
+
end
|
199
|
+
|
200
|
+
should "not add undefined appenders" do
|
201
|
+
outputs = ['my_stdout', 'undefined']
|
202
|
+
log = TestLogger.new(:test, :outputs => outputs)
|
203
|
+
|
204
|
+
assert_equal 1, log.appenders.size
|
205
|
+
end
|
206
|
+
|
207
|
+
private
|
208
|
+
|
209
|
+
def assert_includes_appender(appender_class, logger)
|
210
|
+
assert_includes appender_class, logger.appenders.collect(&:class)
|
211
|
+
end
|
212
|
+
|
213
|
+
def extract_appender_from_logger(logger, type)
|
214
|
+
klass = case type
|
215
|
+
when :syslog
|
216
|
+
Logging::Appenders::Syslog
|
217
|
+
when :file
|
218
|
+
Logging::Appenders::File
|
219
|
+
when :stdout
|
220
|
+
Logging::Appenders::Stdout
|
221
|
+
end
|
222
|
+
|
223
|
+
logger.appenders.detect{ |a| a.is_a?(klass) }
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'assert'
|
2
|
+
require 'logsly/stdout_output'
|
3
|
+
|
2
4
|
require 'ostruct'
|
3
5
|
require 'logging'
|
4
|
-
require 'logsly
|
5
|
-
require 'logsly/stdout_output'
|
6
|
+
require 'logsly'
|
6
7
|
|
7
8
|
class Logsly::StdoutOutput
|
8
9
|
|
9
|
-
class
|
10
|
-
desc "
|
10
|
+
class UnitTests < Assert::Context
|
11
|
+
desc "Logsly::StdoutOutput"
|
11
12
|
setup do
|
12
13
|
@logger = OpenStruct.new
|
13
14
|
@logger.debug_level = :white
|
@@ -22,7 +23,7 @@ class Logsly::StdoutOutput
|
|
22
23
|
colors 'a_color_scheme'
|
23
24
|
end
|
24
25
|
end
|
25
|
-
subject
|
26
|
+
subject{ @out }
|
26
27
|
|
27
28
|
should "be an output handler" do
|
28
29
|
assert_kind_of Logsly::BaseOutput, subject
|
@@ -36,6 +37,7 @@ class Logsly::StdoutOutput
|
|
36
37
|
assert_equal '%d : %m\n', appender.layout.pattern
|
37
38
|
assert_kind_of Logging::ColorScheme, appender.layout.color_scheme
|
38
39
|
end
|
40
|
+
|
39
41
|
end
|
40
42
|
|
41
43
|
end
|
@@ -1,33 +1,15 @@
|
|
1
1
|
require 'assert'
|
2
|
+
require 'logsly/syslog_output'
|
3
|
+
|
2
4
|
require 'ostruct'
|
3
5
|
require 'syslog'
|
4
6
|
require 'logging'
|
5
|
-
require 'logsly
|
6
|
-
require 'logsly/syslog_output'
|
7
|
+
require 'logsly'
|
7
8
|
|
8
9
|
class Logsly::SyslogOutput
|
9
10
|
|
10
|
-
class
|
11
|
-
desc "
|
12
|
-
setup do
|
13
|
-
@data = Logsly::SyslogOutputData.new {}
|
14
|
-
end
|
15
|
-
subject { @data }
|
16
|
-
|
17
|
-
should have_imeth :identity, :log_opts, :facility
|
18
|
-
|
19
|
-
should "default :log_opts" do
|
20
|
-
assert_equal (Syslog::LOG_PID | Syslog::LOG_CONS), subject.log_opts
|
21
|
-
end
|
22
|
-
|
23
|
-
should "default :facility" do
|
24
|
-
assert_equal Syslog::LOG_LOCAL0, subject.facility
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
class BaseTests < Assert::Context
|
30
|
-
desc "the SyslogOutput handler"
|
11
|
+
class UnitTests < Assert::Context
|
12
|
+
desc "Logsly::SyslogOutput"
|
31
13
|
setup do
|
32
14
|
@logger = OpenStruct.new
|
33
15
|
@logger.debug_level = :white
|
@@ -47,7 +29,7 @@ class Logsly::SyslogOutput
|
|
47
29
|
colors 'a_color_scheme'
|
48
30
|
end
|
49
31
|
end
|
50
|
-
subject
|
32
|
+
subject{ @out }
|
51
33
|
|
52
34
|
should "be an output handler" do
|
53
35
|
assert_kind_of Logsly::BaseOutput, subject
|
@@ -61,6 +43,26 @@ class Logsly::SyslogOutput
|
|
61
43
|
assert_equal '%d : %m\n', appender.layout.pattern
|
62
44
|
assert_kind_of Logging::ColorScheme, appender.layout.color_scheme
|
63
45
|
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class SyslogOutputDataTests < Assert::Context
|
50
|
+
desc "SyslogOutputData"
|
51
|
+
setup do
|
52
|
+
@data = Logsly::SyslogOutputData.new {}
|
53
|
+
end
|
54
|
+
subject{ @data }
|
55
|
+
|
56
|
+
should have_imeth :identity, :log_opts, :facility
|
57
|
+
|
58
|
+
should "default :log_opts" do
|
59
|
+
assert_equal (Syslog::LOG_PID | Syslog::LOG_CONS), subject.log_opts
|
60
|
+
end
|
61
|
+
|
62
|
+
should "default :facility" do
|
63
|
+
assert_equal Syslog::LOG_LOCAL0, subject.facility
|
64
|
+
end
|
65
|
+
|
64
66
|
end
|
65
67
|
|
66
68
|
end
|
metadata
CHANGED
@@ -1,80 +1,67 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: logsly
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 1.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Kelly Redding
|
14
8
|
- Collin Redding
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2015-09-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: assert
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 0
|
33
|
-
version: "2.0"
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.15'
|
34
21
|
type: :development
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: ns-options
|
38
22
|
prerelease: false
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.15'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: ns-options
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.1'
|
49
35
|
type: :runtime
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: logging
|
53
36
|
prerelease: false
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.1'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: logging
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.7'
|
64
49
|
type: :runtime
|
65
|
-
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.7'
|
66
56
|
description: Create custom loggers.
|
67
|
-
email:
|
57
|
+
email:
|
68
58
|
- kelly@kellyredding.com
|
69
59
|
- collin.redding@me.com
|
70
60
|
executables: []
|
71
|
-
|
72
61
|
extensions: []
|
73
|
-
|
74
62
|
extra_rdoc_files: []
|
75
|
-
|
76
|
-
|
77
|
-
- .gitignore
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
78
65
|
- Gemfile
|
79
66
|
- LICENSE.txt
|
80
67
|
- README.md
|
@@ -83,62 +70,52 @@ files:
|
|
83
70
|
- lib/logsly/base_output.rb
|
84
71
|
- lib/logsly/colors.rb
|
85
72
|
- lib/logsly/file_output.rb
|
86
|
-
- lib/logsly/settings.rb
|
87
73
|
- lib/logsly/stdout_output.rb
|
88
74
|
- lib/logsly/syslog_output.rb
|
89
75
|
- lib/logsly/version.rb
|
90
76
|
- log/.gitkeep
|
91
77
|
- logsly.gemspec
|
92
78
|
- test/helper.rb
|
79
|
+
- test/support/factory.rb
|
93
80
|
- test/support/logger.rb
|
94
81
|
- test/unit/base_output_tests.rb
|
95
82
|
- test/unit/colors_tests.rb
|
96
83
|
- test/unit/file_output_tests.rb
|
97
|
-
- test/unit/
|
98
|
-
- test/unit/settings_tests.rb
|
84
|
+
- test/unit/logsly_tests.rb
|
99
85
|
- test/unit/stdout_output_tests.rb
|
100
86
|
- test/unit/syslog_output_tests.rb
|
101
87
|
- tmp/.gitkeep
|
102
88
|
homepage: http://github.com/redding/logsly
|
103
|
-
licenses:
|
104
|
-
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
105
92
|
post_install_message:
|
106
93
|
rdoc_options: []
|
107
|
-
|
108
|
-
require_paths:
|
94
|
+
require_paths:
|
109
95
|
- lib
|
110
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
-
|
112
|
-
requirements:
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
113
98
|
- - ">="
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
version: "0"
|
119
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
-
none: false
|
121
|
-
requirements:
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
122
103
|
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
|
125
|
-
segments:
|
126
|
-
- 0
|
127
|
-
version: "0"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
128
106
|
requirements: []
|
129
|
-
|
130
107
|
rubyforge_project:
|
131
|
-
rubygems_version:
|
108
|
+
rubygems_version: 2.4.5
|
132
109
|
signing_key:
|
133
|
-
specification_version:
|
110
|
+
specification_version: 4
|
134
111
|
summary: Create custom loggers.
|
135
|
-
test_files:
|
112
|
+
test_files:
|
136
113
|
- test/helper.rb
|
114
|
+
- test/support/factory.rb
|
137
115
|
- test/support/logger.rb
|
138
116
|
- test/unit/base_output_tests.rb
|
139
117
|
- test/unit/colors_tests.rb
|
140
118
|
- test/unit/file_output_tests.rb
|
141
|
-
- test/unit/
|
142
|
-
- test/unit/settings_tests.rb
|
119
|
+
- test/unit/logsly_tests.rb
|
143
120
|
- test/unit/stdout_output_tests.rb
|
144
121
|
- test/unit/syslog_output_tests.rb
|
data/lib/logsly/settings.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'ns-options'
|
2
|
-
require 'logging'
|
3
|
-
require 'logsly/colors'
|
4
|
-
require 'logsly/base_output'
|
5
|
-
|
6
|
-
module Logsly
|
7
|
-
|
8
|
-
module Settings
|
9
|
-
include NsOptions::Proxy
|
10
|
-
|
11
|
-
option :colors, ::Hash, :default => ::Hash.new(NullColors.new)
|
12
|
-
option :outputs, ::Hash, :default => ::Hash.new(NullOutput.new)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.reset
|
16
|
-
Settings.reset
|
17
|
-
Logging.reset
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.colors(name, &block)
|
21
|
-
require 'logsly/colors'
|
22
|
-
Settings.colors[name.to_s] = Colors.new(name, &block) if !block.nil?
|
23
|
-
Settings.colors[name.to_s]
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.stdout(name, &block)
|
27
|
-
require 'logsly/stdout_output'
|
28
|
-
Settings.outputs[name.to_s] = StdoutOutput.new(&block)
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.file(name, &block)
|
32
|
-
require 'logsly/file_output'
|
33
|
-
Settings.outputs[name.to_s] = FileOutput.new(&block)
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.syslog(name, &block)
|
37
|
-
require 'logsly/syslog_output'
|
38
|
-
Settings.outputs[name.to_s] = SyslogOutput.new(&block)
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.outputs(name)
|
42
|
-
Settings.outputs[name.to_s]
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/test/unit/logger_tests.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'assert'
|
2
|
-
require 'logging'
|
3
|
-
require 'logsly'
|
4
|
-
require 'test/support/logger'
|
5
|
-
|
6
|
-
module Logsly
|
7
|
-
|
8
|
-
class BaseTests < Assert::Context
|
9
|
-
desc "a logger with Logsly mixed in"
|
10
|
-
setup do
|
11
|
-
Logsly.reset
|
12
|
-
@logger = TestLogger.new(:testy_log_logger)
|
13
|
-
end
|
14
|
-
subject { @logger }
|
15
|
-
|
16
|
-
should have_readers :log_type, :level, :outputs, :logger
|
17
|
-
|
18
|
-
should "know its log_type" do
|
19
|
-
assert_equal 'testy_log_logger', subject.log_type
|
20
|
-
end
|
21
|
-
|
22
|
-
should "know its default opt values" do
|
23
|
-
assert_equal 'info', subject.level
|
24
|
-
assert_equal [], subject.outputs
|
25
|
-
end
|
26
|
-
|
27
|
-
should "allow overridding the default opt values" do
|
28
|
-
log = TestLogger.new(:testy_debug_logger, :level => :debug, :outputs => [:stdout])
|
29
|
-
assert_equal 'debug', log.level
|
30
|
-
assert_equal [:stdout], log.outputs
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
class LoggerTests < BaseTests
|
36
|
-
|
37
|
-
should "create a Logging::Logger" do
|
38
|
-
assert_not_nil subject.logger
|
39
|
-
assert_kind_of Logging::Logger, subject.logger
|
40
|
-
end
|
41
|
-
|
42
|
-
should "create the Logging::Logger with a unique name" do
|
43
|
-
expected = "#{subject.class.name}-testy_log_logger-#{subject.object_id}"
|
44
|
-
assert_equal expected, subject.logger.name
|
45
|
-
end
|
46
|
-
|
47
|
-
should "set the logger's level" do
|
48
|
-
assert_equal Logging::LEVELS['info'], subject.logger.level
|
49
|
-
|
50
|
-
log = TestLogger.new('test', :level => :debug)
|
51
|
-
assert_equal Logging::LEVELS['debug'], log.logger.level
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
class AppenderTests < LoggerTests
|
57
|
-
setup do
|
58
|
-
Logsly.stdout 'my_stdout'
|
59
|
-
Logsly.file('my_file') do |logger|
|
60
|
-
path "log/development-#{logger.log_type}.log"
|
61
|
-
end
|
62
|
-
Logsly.file('my_other_file') do |logger|
|
63
|
-
path "log/other-#{logger.log_type}.log"
|
64
|
-
end
|
65
|
-
Logsly.syslog('my_syslog') do |logger|
|
66
|
-
identity "my_syslog_logger-#{logger.log_type}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
should "add a named stdout appender" do
|
71
|
-
log = TestLogger.new(:test, :outputs => 'my_stdout')
|
72
|
-
assert_includes_appender Logging::Appenders::Stdout, log
|
73
|
-
end
|
74
|
-
|
75
|
-
should "add a named file appender" do
|
76
|
-
log = TestLogger.new(:test, :outputs => 'my_file')
|
77
|
-
filelog = extract_appender_from_logger(log, :file)
|
78
|
-
|
79
|
-
assert_includes_appender Logging::Appenders::File, log
|
80
|
-
assert_equal 'log/development-test.log', filelog.name
|
81
|
-
end
|
82
|
-
|
83
|
-
should "add a named syslog appender" do
|
84
|
-
log = TestLogger.new(:test, :outputs => 'my_syslog')
|
85
|
-
assert_includes_appender Logging::Appenders::Syslog, log
|
86
|
-
end
|
87
|
-
|
88
|
-
should "not add duplicate appenders" do
|
89
|
-
outputs = ['my_stdout', 'my_stdout', 'my_file', 'my_other_file']
|
90
|
-
log = TestLogger.new(:test, :outputs => outputs)
|
91
|
-
|
92
|
-
assert_equal 3, log.appenders.size
|
93
|
-
end
|
94
|
-
|
95
|
-
should "not add undefined appenders" do
|
96
|
-
outputs = ['my_stdout', 'undefined']
|
97
|
-
log = TestLogger.new(:test, :outputs => outputs)
|
98
|
-
|
99
|
-
assert_equal 1, log.appenders.size
|
100
|
-
end
|
101
|
-
|
102
|
-
protected
|
103
|
-
|
104
|
-
def assert_includes_appender(appender_class, logger)
|
105
|
-
assert_includes appender_class, logger.appenders.collect(&:class)
|
106
|
-
end
|
107
|
-
|
108
|
-
def extract_appender_from_logger(logger, type)
|
109
|
-
klass = case type
|
110
|
-
when :syslog
|
111
|
-
Logging::Appenders::Syslog
|
112
|
-
when :file
|
113
|
-
Logging::Appenders::File
|
114
|
-
when :stdout
|
115
|
-
Logging::Appenders::Stdout
|
116
|
-
end
|
117
|
-
|
118
|
-
logger.appenders.select{|a| a.is_a?(klass)}.first
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
data/test/unit/settings_tests.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'assert'
|
2
|
-
require 'logsly/settings'
|
3
|
-
|
4
|
-
module Logsly
|
5
|
-
|
6
|
-
class SettingsTests < Assert::Context
|
7
|
-
desc "Logsly settings"
|
8
|
-
setup do
|
9
|
-
Logsly::Settings.reset
|
10
|
-
end
|
11
|
-
subject { Logsly }
|
12
|
-
|
13
|
-
should have_imeths :reset, :colors, :stdout, :file, :syslog, :outputs
|
14
|
-
|
15
|
-
should "return a NullColors obj when requesting a color scheme that isn't defined" do
|
16
|
-
assert_kind_of NullColors, Logsly.colors('not_defined_yet')
|
17
|
-
end
|
18
|
-
|
19
|
-
should "return a NullOutput obj when requesting an output that isn't defined" do
|
20
|
-
assert_kind_of NullOutput, Logsly.outputs('not_defined_yet')
|
21
|
-
end
|
22
|
-
|
23
|
-
should "add a named color scheme using the `colors` method" do
|
24
|
-
assert_kind_of NullColors, Logsly.colors('test_colors')
|
25
|
-
Logsly.colors('test_colors') {}
|
26
|
-
|
27
|
-
assert_kind_of Colors, Logsly.colors('test_colors')
|
28
|
-
end
|
29
|
-
|
30
|
-
should "add a named stdout output using the `stdout` method" do
|
31
|
-
assert_kind_of NullOutput, Logsly.outputs('test_stdout')
|
32
|
-
Logsly.stdout('test_stdout') {}
|
33
|
-
|
34
|
-
assert_not_nil Logsly.outputs('test_stdout')
|
35
|
-
assert_kind_of StdoutOutput, Logsly.outputs('test_stdout')
|
36
|
-
end
|
37
|
-
|
38
|
-
should "add a named file output using the `file` method" do
|
39
|
-
assert_kind_of NullOutput, Logsly.outputs('test_file')
|
40
|
-
Logsly.file('test_file') {}
|
41
|
-
|
42
|
-
assert_not_nil Logsly.outputs('test_file')
|
43
|
-
assert_kind_of FileOutput, Logsly.outputs('test_file')
|
44
|
-
end
|
45
|
-
|
46
|
-
should "add a named syslog output using the `syslog` method" do
|
47
|
-
assert_kind_of NullOutput, Logsly.outputs('test_syslog')
|
48
|
-
Logsly.syslog('test_syslog') {}
|
49
|
-
|
50
|
-
assert_not_nil Logsly.outputs('test_syslog')
|
51
|
-
assert_kind_of SyslogOutput, Logsly.outputs('test_syslog')
|
52
|
-
end
|
53
|
-
|
54
|
-
should "convert non-string setting names to string" do
|
55
|
-
Logsly.colors(:test_colors) {}
|
56
|
-
|
57
|
-
assert_not_nil Logsly.colors(:test_colors)
|
58
|
-
assert_kind_of Colors, Logsly.colors(:test_colors)
|
59
|
-
end
|
60
|
-
|
61
|
-
should "overwrite same-named colors settings" do
|
62
|
-
Logsly.colors('something') {}
|
63
|
-
orig = Logsly.colors('something')
|
64
|
-
Logsly.colors('something') {}
|
65
|
-
|
66
|
-
assert_not_same orig, Logsly.colors('something')
|
67
|
-
end
|
68
|
-
|
69
|
-
should "overwrite same-named outputs settings" do
|
70
|
-
Logsly.stdout('something') {}
|
71
|
-
assert_kind_of StdoutOutput, Logsly.outputs('something')
|
72
|
-
|
73
|
-
Logsly.file('something') {}
|
74
|
-
assert_kind_of FileOutput, Logsly.outputs('something')
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
class ResetTests < SettingsTests
|
80
|
-
desc "`reset` method"
|
81
|
-
setup do
|
82
|
-
Logsly.colors('test_colors') {}
|
83
|
-
Logsly.stdout('test_stdout') {}
|
84
|
-
end
|
85
|
-
|
86
|
-
should "reset the Settings" do
|
87
|
-
assert_kind_of Colors, Logsly.colors('test_colors')
|
88
|
-
assert_kind_of StdoutOutput, Logsly.outputs('test_stdout')
|
89
|
-
|
90
|
-
Logsly.reset
|
91
|
-
|
92
|
-
assert_kind_of NullColors, Logsly.colors('test_colors')
|
93
|
-
assert_kind_of NullOutput, Logsly.outputs('test_stdout')
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|