logsly 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,242 @@
1
+ require 'assert'
2
+ require 'logsly/outputs'
3
+
4
+ require 'logging'
5
+ require 'logsly'
6
+
7
+ module Logsly::Outputs
8
+
9
+ class UnitTests < Assert::Context
10
+ desc "Logsly::Outputs"
11
+
12
+ end
13
+
14
+ class BaseTests < UnitTests
15
+ desc "Base"
16
+ setup do
17
+ @out = Base.new
18
+ end
19
+ subject{ @out }
20
+
21
+ should have_reader :build
22
+ should have_imeths :to_layout, :to_appender
23
+
24
+ should "know its build" do
25
+ build_proc = Proc.new{}
26
+ out = Base.new(&build_proc)
27
+
28
+ assert_same build_proc, out.build
29
+ end
30
+
31
+ should "expect `to_appender` to be defined by subclasses" do
32
+ assert_raises NotImplementedError do
33
+ subject.to_appender
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ class BaseBuildTests < BaseTests
40
+ desc "given a build"
41
+ setup do
42
+ Logsly.colors('a_color_scheme') do
43
+ debug :white
44
+ end
45
+ @out = Base.new do |*args|
46
+ pattern args.to_s
47
+ colors 'a_color_scheme'
48
+ end
49
+ end
50
+
51
+ should "build a Logging pattern layout" do
52
+ data = BaseData.new('%d : %m\n', &@out.build)
53
+ lay = subject.to_layout(data)
54
+
55
+ assert_kind_of Logging::Layout, lay
56
+ assert_equal '%d : %m\n', lay.pattern
57
+ assert_kind_of Logging::ColorScheme, lay.color_scheme
58
+ end
59
+
60
+ end
61
+
62
+ class BaseDataTests < UnitTests
63
+ desc "BaseData"
64
+ setup do
65
+ Logsly.colors('a_color_scheme') do
66
+ debug :white
67
+ end
68
+ @arg = '%d : %m\n'
69
+ @data = BaseData.new(@arg) do |*args|
70
+ pattern args.first
71
+ colors 'a_color_scheme'
72
+ end
73
+ end
74
+ subject{ @data }
75
+
76
+ should have_imeths :pattern, :colors
77
+
78
+ should "know its defaults" do
79
+ data = BaseData.new
80
+ assert_equal '%m\n', data.pattern
81
+ assert_nil data.colors
82
+ end
83
+
84
+ should "instance exec its build with args" do
85
+ assert_equal '%d : %m\n', subject.pattern
86
+ assert_equal 'a_color_scheme', subject.colors
87
+ end
88
+
89
+ should "know its layout pattern opts hash" do
90
+ exp = {
91
+ :pattern => subject.pattern,
92
+ :color_scheme => "#{subject.colors}-#{@arg.object_id}"
93
+ }
94
+ assert_equal exp, subject.to_pattern_opts
95
+
96
+ data = BaseData.new{ pattern '%m\n' }
97
+ exp = { :pattern => data.pattern }
98
+ assert_equal exp, data.to_pattern_opts
99
+ end
100
+
101
+ end
102
+
103
+ class StdoutTests < UnitTests
104
+ desc "Stdout"
105
+ setup do
106
+ @logger = OpenStruct.new
107
+ @logger.debug_level = :white
108
+ @logger.pattern = '%d : %m\n'
109
+
110
+ Logsly.colors('a_color_scheme') do |logger|
111
+ debug logger.debug_level
112
+ end
113
+
114
+ @out = Stdout.new do |logger|
115
+ pattern logger.pattern
116
+ colors 'a_color_scheme'
117
+ end
118
+ end
119
+ subject{ @out }
120
+
121
+ should "be a Base output" do
122
+ assert_kind_of Base, subject
123
+ end
124
+
125
+ should "build a Logging stdout appender, passing args to the builds" do
126
+ appender = subject.to_appender @logger
127
+
128
+ assert_kind_of Logging::Appenders::Stdout, appender
129
+ assert_kind_of Logging::Layouts::Pattern, appender.layout
130
+ assert_equal '%d : %m\n', appender.layout.pattern
131
+ assert_kind_of Logging::ColorScheme, appender.layout.color_scheme
132
+ end
133
+
134
+ end
135
+
136
+ class FileTests < UnitTests
137
+ desc "File"
138
+ setup do
139
+ @logger = OpenStruct.new
140
+ @logger.debug_level = :white
141
+ @logger.pattern = '%d : %m\n'
142
+ @logger.file = "log/dev.log"
143
+
144
+ Logsly.colors('a_color_scheme') do |logger|
145
+ debug logger.debug_level
146
+ end
147
+
148
+ @out = File.new do |logger|
149
+ path logger.file
150
+
151
+ pattern logger.pattern
152
+ colors 'a_color_scheme'
153
+ end
154
+ end
155
+ subject{ @out }
156
+
157
+ should "be a Base output" do
158
+ assert_kind_of Base, subject
159
+ end
160
+
161
+ should "build a Logging file appender, passing args to the builds" do
162
+ appender = subject.to_appender @logger
163
+
164
+ assert_kind_of Logging::Appenders::File, appender
165
+ assert_equal 'log/dev.log', appender.name
166
+ assert_kind_of Logging::Layouts::Pattern, appender.layout
167
+ assert_equal '%d : %m\n', appender.layout.pattern
168
+ assert_kind_of Logging::ColorScheme, appender.layout.color_scheme
169
+ end
170
+
171
+ end
172
+
173
+ class FileDataTests < UnitTests
174
+ desc "FilData"
175
+ setup do
176
+ @data = FileData.new
177
+ end
178
+ subject{ @data }
179
+
180
+ should have_imeths :path
181
+
182
+ end
183
+
184
+ class SyslogTests < UnitTests
185
+ desc "SyslogTests"
186
+ setup do
187
+ @logger = OpenStruct.new
188
+ @logger.debug_level = :white
189
+ @logger.pattern = '%d : %m\n'
190
+ @logger.identity = "whatever"
191
+ @logger.facility = ::Syslog::LOG_LOCAL3
192
+
193
+ Logsly.colors('a_color_scheme') do |logger|
194
+ debug logger.debug_level
195
+ end
196
+
197
+ @out = Syslog.new do |logger|
198
+ identity logger.identity
199
+ facility logger.facility
200
+
201
+ pattern logger.pattern
202
+ colors 'a_color_scheme'
203
+ end
204
+ end
205
+ subject{ @out }
206
+
207
+ should "be a Base output" do
208
+ assert_kind_of Base, subject
209
+ end
210
+
211
+ should "build a Logging syslog appender, passing args to the builds" do
212
+ appender = subject.to_appender @logger
213
+
214
+ assert_kind_of Logging::Appenders::Syslog, appender
215
+ assert_kind_of Logging::Layouts::Pattern, appender.layout
216
+ assert_equal '%d : %m\n', appender.layout.pattern
217
+ assert_kind_of Logging::ColorScheme, appender.layout.color_scheme
218
+ end
219
+
220
+ end
221
+
222
+ class SyslogDataTests < UnitTests
223
+ desc "SyslogData"
224
+ setup do
225
+ @data = SyslogData.new
226
+ end
227
+ subject{ @data }
228
+
229
+ should have_imeth :identity, :log_opts, :facility
230
+
231
+ should "default :log_opts" do
232
+ assert_equal (::Syslog::LOG_PID | ::Syslog::LOG_CONS), subject.log_opts
233
+ end
234
+
235
+ should "default :facility" do
236
+ assert_equal ::Syslog::LOG_LOCAL0, subject.facility
237
+ end
238
+
239
+ end
240
+
241
+ end
242
+
metadata CHANGED
@@ -1,121 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: logsly
3
- version: !ruby/object:Gem::Version
4
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Kelly Redding
8
8
  - Collin Redding
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-01 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2016-06-13 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: assert
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '2.15'
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 2.16.1
21
23
  type: :development
24
+ version_requirements: *id001
25
+ - !ruby/object:Gem::Dependency
26
+ name: much-plugin
22
27
  prerelease: false
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'
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.2.0
35
33
  type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '1.1'
42
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
43
36
  name: logging
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '1.7'
49
- type: :runtime
50
37
  prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '1.7'
38
+ requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: "1.7"
43
+ type: :runtime
44
+ version_requirements: *id003
56
45
  description: Create custom loggers.
57
- email:
46
+ email:
58
47
  - kelly@kellyredding.com
59
48
  - collin.redding@me.com
60
49
  executables: []
50
+
61
51
  extensions: []
52
+
62
53
  extra_rdoc_files: []
63
- files:
64
- - ".gitignore"
54
+
55
+ files:
56
+ - .gitignore
65
57
  - Gemfile
66
- - LICENSE.txt
58
+ - LICENSE
67
59
  - README.md
68
- - Rakefile
69
60
  - lib/logsly.rb
70
- - lib/logsly/base_output.rb
71
61
  - lib/logsly/colors.rb
72
- - lib/logsly/file_output.rb
73
- - lib/logsly/stdout_output.rb
74
- - lib/logsly/syslog_output.rb
62
+ - lib/logsly/outputs.rb
75
63
  - lib/logsly/version.rb
76
64
  - log/.gitkeep
77
65
  - logsly.gemspec
78
66
  - test/helper.rb
79
67
  - test/support/factory.rb
80
68
  - test/support/logger.rb
81
- - test/unit/base_output_tests.rb
82
69
  - test/unit/colors_tests.rb
83
- - test/unit/file_output_tests.rb
84
70
  - test/unit/logsly_tests.rb
85
- - test/unit/stdout_output_tests.rb
86
- - test/unit/syslog_output_tests.rb
71
+ - test/unit/outputs_tests.rb
87
72
  - tmp/.gitkeep
88
73
  homepage: http://github.com/redding/logsly
89
- licenses:
74
+ licenses:
90
75
  - MIT
91
76
  metadata: {}
77
+
92
78
  post_install_message:
93
79
  rdoc_options: []
94
- require_paths:
80
+
81
+ require_paths:
95
82
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: '0'
101
- required_rubygems_version: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - &id004
86
+ - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - *id004
106
92
  requirements: []
93
+
107
94
  rubyforge_project:
108
- rubygems_version: 2.4.5
95
+ rubygems_version: 2.6.4
109
96
  signing_key:
110
97
  specification_version: 4
111
98
  summary: Create custom loggers.
112
- test_files:
99
+ test_files:
113
100
  - test/helper.rb
114
101
  - test/support/factory.rb
115
102
  - test/support/logger.rb
116
- - test/unit/base_output_tests.rb
117
103
  - test/unit/colors_tests.rb
118
- - test/unit/file_output_tests.rb
119
104
  - test/unit/logsly_tests.rb
120
- - test/unit/stdout_output_tests.rb
121
- - test/unit/syslog_output_tests.rb
105
+ - test/unit/outputs_tests.rb
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -1,64 +0,0 @@
1
- require 'ostruct'
2
- require 'ns-options'
3
- require 'logging'
4
-
5
- module Logsly
6
-
7
- class NullOutput < OpenStruct
8
- def to_appender(*args); nil; end
9
- def to_layout(*args); nil; end
10
- end
11
-
12
- class BaseOutput
13
-
14
- attr_reader :build
15
-
16
- def initialize(&build)
17
- @build = build || Proc.new {}
18
- end
19
-
20
- def to_appender(*args)
21
- self.instance_exec(*args, &@build)
22
- self.colors_obj.run_build(*args)
23
- self
24
- end
25
-
26
- def to_layout(data)
27
- Logging.layouts.pattern(data.to_pattern_opts)
28
- end
29
-
30
- def to_appender(*args)
31
- raise NotImplementedError
32
- end
33
-
34
- end
35
-
36
- class BaseOutputData
37
- include NsOptions::Proxy
38
- option :pattern, String, :default => '%m\n'
39
- option :colors, String
40
-
41
- def initialize(*args, &build)
42
- @args = args
43
- self.instance_exec(*@args, &build)
44
- end
45
-
46
- def to_pattern_opts
47
- Hash.new.tap do |opts|
48
- opts[:pattern] = self.pattern if self.pattern
49
-
50
- if scheme_name = colors_obj.to_scheme(*@args)
51
- opts[:color_scheme] = scheme_name
52
- end
53
- end
54
- end
55
-
56
- protected
57
-
58
- def colors_obj
59
- Logsly.colors(self.colors)
60
- end
61
-
62
- end
63
-
64
- end
@@ -1,17 +0,0 @@
1
- require 'logging'
2
- require 'logsly/base_output'
3
-
4
- module Logsly
5
-
6
- class FileOutput < BaseOutput
7
- def to_appender(*args)
8
- data = FileOutputData.new(*args, &self.build)
9
- Logging.appenders.file(data.path, :layout => self.to_layout(data))
10
- end
11
- end
12
-
13
- class FileOutputData < BaseOutputData
14
- option :path, String
15
- end
16
-
17
- end
@@ -1,13 +0,0 @@
1
- require 'logging'
2
- require 'logsly/base_output'
3
-
4
- module Logsly
5
-
6
- class StdoutOutput < BaseOutput
7
- def to_appender(*args)
8
- data = BaseOutputData.new(*args, &self.build)
9
- Logging.appenders.stdout(:layout => self.to_layout(data))
10
- end
11
- end
12
-
13
- end
@@ -1,26 +0,0 @@
1
- require 'syslog'
2
- require 'logging'
3
- require 'logsly/base_output'
4
-
5
- module Logsly
6
-
7
- class SyslogOutput < BaseOutput
8
- def to_appender(*args)
9
- Syslog.close if Syslog.opened?
10
-
11
- data = SyslogOutputData.new(*args, &self.build)
12
- Logging.appenders.syslog(data.identity, {
13
- :logopt => data.log_opts,
14
- :facility => data.facility,
15
- :layout => self.to_layout(data)
16
- })
17
- end
18
- end
19
-
20
- class SyslogOutputData < BaseOutputData
21
- option :identity, String
22
- option :log_opts, Integer, :default => (Syslog::LOG_PID | Syslog::LOG_CONS)
23
- option :facility, Integer, :default => Syslog::LOG_LOCAL0
24
- end
25
-
26
- end
@@ -1,101 +0,0 @@
1
- require 'assert'
2
- require 'logsly/base_output'
3
-
4
- require 'logging'
5
- require 'logsly'
6
-
7
- class Logsly::BaseOutput
8
-
9
- class UnitTests < Assert::Context
10
- desc "Logsly::BaseOutput"
11
- setup do
12
- @out = Logsly::BaseOutput.new {}
13
- end
14
- subject{ @out }
15
-
16
- should have_reader :build
17
- should have_imeths :to_layout, :to_appender
18
-
19
- should "know its build" do
20
- build_proc = Proc.new {}
21
- out = Logsly::BaseOutput.new &build_proc
22
-
23
- assert_same build_proc, out.build
24
- end
25
-
26
- should "expect `to_appender` to be defined by subclasses" do
27
- assert_raises NotImplementedError do
28
- subject.to_appender
29
- end
30
- end
31
-
32
- end
33
-
34
- class BuildTests < UnitTests
35
- desc "given a build"
36
- setup do
37
- Logsly.colors('a_color_scheme') do
38
- debug :white
39
- end
40
- @out = Logsly::BaseOutput.new do |*args|
41
- pattern args.to_s
42
- colors 'a_color_scheme'
43
- end
44
- end
45
-
46
- should "build a Logging pattern layout" do
47
- data = Logsly::BaseOutputData.new('%d : %m\n', &@out.build)
48
- lay = subject.to_layout(data)
49
-
50
- assert_kind_of Logging::Layout, lay
51
- assert_equal '%d : %m\n', lay.pattern
52
- assert_kind_of Logging::ColorScheme, lay.color_scheme
53
- end
54
-
55
- end
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
-
100
- end
101
-
@@ -1,58 +0,0 @@
1
- require 'assert'
2
- require 'logsly/file_output'
3
-
4
- require 'logging'
5
- require 'ostruct'
6
- require 'logsly'
7
-
8
- class Logsly::FileOutput
9
-
10
- class UnitTests < Assert::Context
11
- desc "Logsly::FileOutput"
12
- setup do
13
- @logger = OpenStruct.new
14
- @logger.debug_level = :white
15
- @logger.pattern = '%d : %m\n'
16
- @logger.file = "log/dev.log"
17
-
18
- Logsly.colors('a_color_scheme') do |logger|
19
- debug logger.debug_level
20
- end
21
-
22
- @out = Logsly::FileOutput.new do |logger|
23
- path logger.file
24
-
25
- pattern logger.pattern
26
- colors 'a_color_scheme'
27
- end
28
- end
29
- subject{ @out }
30
-
31
- should "be an output handler" do
32
- assert_kind_of Logsly::BaseOutput, subject
33
- end
34
-
35
- should "build a Logging file appender, passing args to the builds" do
36
- appender = subject.to_appender @logger
37
-
38
- assert_kind_of Logging::Appenders::File, appender
39
- assert_equal 'log/dev.log', appender.name
40
- assert_kind_of Logging::Layouts::Pattern, appender.layout
41
- assert_equal '%d : %m\n', appender.layout.pattern
42
- assert_kind_of Logging::ColorScheme, appender.layout.color_scheme
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
-
56
- end
57
-
58
- end