leafy-logger 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fb1b3ecc2a5c3c68c5404d5f9700725d781d2df
4
- data.tar.gz: 1410c3e6942ae9320af895fb9de2c2bb70d61483
3
+ metadata.gz: 1edaf8d266b154d77138726bca83c4f088e6ba5c
4
+ data.tar.gz: 76fc9235ef72622badaa6b960bcf22963a54ac93
5
5
  SHA512:
6
- metadata.gz: 9ed23422d8fc080194cf5eea536708a9f01846cfa3e8d064d566ee2e98ee587156b01376d9950c64b59347ae95358375cf06b81de928678c5da110d50751ebae
7
- data.tar.gz: 702de8a2429274722894c946eac8a1f88f58200dc314632bf062a59456b36ade2bc9a92c3bebf7db11f6baa27099a0f23effc1d3d66f425d05631e8c257012b1
6
+ metadata.gz: 2b306aa5c14cb9c2f100954926cce76e99870abcb83b0bf510ad414aef34877588779ea6d094f0ac118889e54ec17cfa9e6402ff805cbedfc31b802eb3181c3c
7
+ data.tar.gz: d2cc30bf437d1d6d75e57b54742833815ef1005045e45ee9b0ef6472c2fe6a096ccdc3fa88c069a5d3e381f65973db9f5f6457fed12e3858d2069733318393b4
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  doc
3
3
  pkg
4
4
  *.lock
5
+ logs
data/README.md CHANGED
@@ -104,6 +104,58 @@ appender = Leafy::Logger::SyslogAppenderFactory.new do
104
104
  end
105
105
  ```
106
106
 
107
+ # using configurations
108
+
109
+ a yaml file or an options hash can be used to configure the logger factory. once you have a logger factory you can reconfigure it with a yaml-file or options hash at runtime.
110
+
111
+ ## build logger factory from yaml file
112
+
113
+ having a yaml file like (config/logging.yaml)
114
+
115
+ ```
116
+ level: ERROR
117
+ loggers:
118
+ com.example.app: DEBUG
119
+ com.example.db: INFO
120
+ appenders:
121
+ - type: console
122
+ threshold: DEBUG
123
+ target: STDERR
124
+ - type: file
125
+ threshold: INFO
126
+ currentLogFilename: ./logs/example.log
127
+ archivedLogFilenamePattern: ./logs/example-%d.log.gz
128
+ archivedFileCount: 12
129
+ - type: syslog
130
+ host: 127.0.0.1
131
+ port: 123
132
+ facility: KERN
133
+ ```
134
+ can be used to build ```LoggerFactory``` directly from this yaml file:
135
+
136
+ ```
137
+ factory = Leafy::Logger::Factory.new_from_yaml( 'config/logging.yaml' )
138
+ ```
139
+
140
+ having the same config as ```Hash``` can be used as well
141
+
142
+ ```
143
+ options = YAML.load( File.read( 'config/logging.yaml' ) )
144
+ factory = Leafy::Logger::Factory.new_from_options( options )
145
+ ```
146
+
147
+ ## reconfigure logger factory at runtime
148
+
149
+ ```
150
+ factory.reconfigure_from_yaml( 'config/logging.yaml' )
151
+ ```
152
+
153
+ or
154
+
155
+ ```
156
+ factory.reconfigure_from_options( options )
157
+ ```
158
+
107
159
  ## developement
108
160
 
109
161
  get all the gems and jars in place
@@ -2,10 +2,12 @@ require 'leafy/logger'
2
2
  require 'leafy/logger/appender_factories'
3
3
  require 'yaml'
4
4
  require 'stringio'
5
+ require 'jruby/synchronized'
5
6
 
6
7
  module Leafy
7
8
  module Logger
8
9
  class Factory
10
+ include JRuby::Synchronized
9
11
 
10
12
  class HashSourceProvider
11
13
  include Java::IoDropwizardConfiguration::ConfigurationSourceProvider
@@ -33,8 +35,8 @@ module Leafy
33
35
  Java::IoDropwizardConfiguration::ConfigurationFactory.new( Java::IoDropwizardLogging::LoggingFactory.java_class, validator, objectMapper, "" )
34
36
  end
35
37
 
36
- def self.new_from( hash )
37
- new( configurator.build( HashSourceProvider.new( hash ), 'dummy') )
38
+ def self.new_from_options( options )
39
+ new( configurator.build( HashSourceProvider.new( options ), 'dummy') )
38
40
  end
39
41
 
40
42
  def self.new_from_yaml( yamlfile )
@@ -46,6 +48,22 @@ module Leafy
46
48
  @factory = factory || Java::IoDropwizardLogging::LoggingFactory.new
47
49
  end
48
50
 
51
+ def reconfigure_from_options( options )
52
+ do_reconfigure( self.class.configurator.build( HashSourceProvider.new( options ), 'dummy') )
53
+ end
54
+
55
+ def reconfigure_from_yaml( yamlfile )
56
+ raise "no such file #{yamlfile}" unless File.exists?( yamlfile )
57
+ do_reconfigure( self.class.configurator.build( java.io.File.new( yamlfile ) ) )
58
+ end
59
+
60
+ def do_reconfigure( factory )
61
+ @factory.stop
62
+ @factory = factory
63
+ reconfigure
64
+ end
65
+ private :do_reconfigure
66
+
49
67
  def level args = nil
50
68
  if args
51
69
  self.level = args
@@ -54,6 +72,12 @@ module Leafy
54
72
  end
55
73
  end
56
74
 
75
+ def level_set level
76
+ l = level.to_s.upcase
77
+ @factory.level = Java::ChQosLogbackClassic::Level.const_get( l )
78
+ end
79
+ private :level_set
80
+
57
81
  def level= level
58
82
  l = level.to_s.upcase
59
83
  @factory.level = Java::ChQosLogbackClassic::Level.const_get( l )
@@ -87,10 +111,15 @@ module Leafy
87
111
  self.loggers = m
88
112
  end
89
113
 
90
- def loggers= map
114
+ def loggers_set map
91
115
  m = {}
92
116
  map.each { |k,v| m[k] = Java::ChQosLogbackClassic::Level.const_get( v.to_s.upcase ) }
93
117
  @factory.loggers = m
118
+ end
119
+ private :loggers_set
120
+
121
+ def loggers= map
122
+ loggers_set( map )
94
123
  reconfigure
95
124
  end
96
125
 
@@ -1,6 +1,6 @@
1
1
  module Leafy
2
2
  module Logger
3
- VERSION = '0.2.1'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
6
6
 
@@ -17,6 +17,19 @@ describe Leafy::Logger::Factory do
17
17
  let( :logger1 ) { Leafy::Logger::Factory.get_logger 'my.app' }
18
18
  let( :logger2 ) { Leafy::Logger::Factory.get_logger 'my.db' }
19
19
 
20
+ let( :factory_yaml ) { Leafy::Logger::Factory.new_from_yaml( yaml ) }
21
+ let( :reconfigured_yaml ) do
22
+ subject.reconfigure_from_yaml( yaml )
23
+ subject
24
+ end
25
+
26
+ let( :options ) { YAML.load( File.read( yaml ) ) }
27
+ let( :factory_options ) { Leafy::Logger::Factory.new_from_options( options ) }
28
+ let( :reconfigured_options ) do
29
+ subject.reconfigure_from_options( options )
30
+ subject
31
+ end
32
+
20
33
  before { FileUtils.rm_f log }
21
34
  after { FileUtils.rm_f log }
22
35
 
@@ -115,41 +128,49 @@ describe Leafy::Logger::Factory do
115
128
  expect {Leafy::Logger::Factory.new_from_yaml( yaml + '.gone' ) }.to raise_error( Exception )
116
129
  end
117
130
 
118
- it 'can use a yaml configuration' do
119
- f = Leafy::Logger::Factory.new_from_yaml( yaml )
120
- expect( f.level ).to eq 'ERROR'
121
- expect( f.loggers ).to eq 'com.example.app' => 'DEBUG'
122
- expect( f.appenders.size ).to eq 3
123
- # console
124
- expect( f.appenders[0].threshold ).to eq 'DEBUG'
125
- expect( f.appenders[0].target ).to eq 'STDERR'
126
- # file
127
- expect( f.appenders[1].threshold ).to eq 'INFO'
128
- expect( f.appenders[1].current_log_filename ).to eq './logs/example.log'
129
- expect( f.appenders[1].archived_log_filename_pattern ).to eq './logs/example-%d.log.gz'
130
- expect( f.appenders[1].archived_file_count ).to eq 12
131
- # syslog
132
- expect( f.appenders[2].host ).to eq 'myhost'
133
- expect( f.appenders[2].port ).to eq 123
134
- expect( f.appenders[2].facility ).to eq 'KERN'
131
+ it 'fails reconfigure on missing yaml configuration' do
132
+ expect {subject.reconfigure_from_yaml( yaml + '.gone' ) }.to raise_error( Exception )
135
133
  end
136
134
 
137
- it 'can use a hash configuration' do
138
- f = Leafy::Logger::Factory.new_from( YAML.load( File.read( yaml ) ) )
139
- expect( f.level ).to eq 'ERROR'
140
- expect( f.loggers ).to eq 'com.example.app' => 'DEBUG'
141
- expect( f.appenders.size ).to eq 3
142
- # console
143
- expect( f.appenders[0].threshold ).to eq 'DEBUG'
144
- expect( f.appenders[0].target ).to eq 'STDERR'
145
- # file
146
- expect( f.appenders[1].threshold ).to eq 'INFO'
147
- expect( f.appenders[1].current_log_filename ).to eq './logs/example.log'
148
- expect( f.appenders[1].archived_log_filename_pattern ).to eq './logs/example-%d.log.gz'
149
- expect( f.appenders[1].archived_file_count ).to eq 12
150
- # syslog
151
- expect( f.appenders[2].host ).to eq 'myhost'
152
- expect( f.appenders[2].port ).to eq 123
153
- expect( f.appenders[2].facility ).to eq 'KERN'
135
+ [ :factory_yaml, :reconfigured_yaml ].each do |method|
136
+ it "can use a yaml configuration - #{method}" do
137
+ f = send( method )
138
+ expect( f.level ).to eq 'ERROR'
139
+ expect( f.loggers ).to eq 'com.example.app' => 'DEBUG'
140
+ expect( f.appenders.size ).to eq 3
141
+ # console
142
+ expect( f.appenders[0].threshold ).to eq 'DEBUG'
143
+ expect( f.appenders[0].target ).to eq 'STDERR'
144
+ # file
145
+ expect( f.appenders[1].threshold ).to eq 'INFO'
146
+ expect( f.appenders[1].current_log_filename ).to eq './logs/example.log'
147
+ expect( f.appenders[1].archived_log_filename_pattern ).to eq './logs/example-%d.log.gz'
148
+ expect( f.appenders[1].archived_file_count ).to eq 12
149
+ # syslog
150
+ expect( f.appenders[2].host ).to eq '127.0.0.1'
151
+ expect( f.appenders[2].port ).to eq 123
152
+ expect( f.appenders[2].facility ).to eq 'KERN'
153
+ end
154
+ end
155
+
156
+ [ :factory_options, :reconfigured_options ].each do |method|
157
+ it 'can use a hash configuration' do
158
+ f = send( method )
159
+ expect( f.level ).to eq 'ERROR'
160
+ expect( f.loggers ).to eq 'com.example.app' => 'DEBUG'
161
+ expect( f.appenders.size ).to eq 3
162
+ # console
163
+ expect( f.appenders[0].threshold ).to eq 'DEBUG'
164
+ expect( f.appenders[0].target ).to eq 'STDERR'
165
+ # file
166
+ expect( f.appenders[1].threshold ).to eq 'INFO'
167
+ expect( f.appenders[1].current_log_filename ).to eq './logs/example.log'
168
+ expect( f.appenders[1].archived_log_filename_pattern ).to eq './logs/example-%d.log.gz'
169
+ expect( f.appenders[1].archived_file_count ).to eq 12
170
+ # syslog
171
+ expect( f.appenders[2].host ).to eq '127.0.0.1'
172
+ expect( f.appenders[2].port ).to eq 123
173
+ expect( f.appenders[2].facility ).to eq 'KERN'
174
+ end
154
175
  end
155
176
  end
@@ -11,6 +11,6 @@ appenders:
11
11
  archivedLogFilenamePattern: ./logs/example-%d.log.gz
12
12
  archivedFileCount: 12
13
13
  - type: syslog
14
- host: myhost
14
+ host: 127.0.0.1
15
15
  port: 123
16
16
  facility: KERN
metadata CHANGED
@@ -1,93 +1,94 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leafy-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian meier
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: jar-dependencies
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - ~>
17
+ - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: 0.1.8
19
- name: jar-dependencies
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.1.8
27
27
  - !ruby/object:Gem::Dependency
28
+ name: leafy-metrics
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: 0.2.0
33
- name: leafy-metrics
34
- prerelease: false
35
34
  type: :runtime
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rspec
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - ~>
45
+ - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: 3.1.0
47
- name: rspec
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.1.0
55
55
  - !ruby/object:Gem::Dependency
56
+ name: yard
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - ~>
59
+ - - "~>"
59
60
  - !ruby/object:Gem::Version
60
61
  version: 0.8.7
61
- name: yard
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.8.7
69
69
  - !ruby/object:Gem::Dependency
70
+ name: rake
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - ~>
73
+ - - "~>"
73
74
  - !ruby/object:Gem::Version
74
75
  version: '10.2'
75
- name: rake
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.2'
83
- description: adding logback to leafy with yaml configuration and bridges to log4j and jul
83
+ description: adding logback to leafy with yaml configuration and bridges to log4j
84
+ and jul
84
85
  email:
85
86
  - christian.meier@lookout.com
86
87
  executables: []
87
88
  extensions: []
88
89
  extra_rdoc_files: []
89
90
  files:
90
- - .gitignore
91
+ - ".gitignore"
91
92
  - Gemfile
92
93
  - LICENSE
93
94
  - README.md
@@ -107,27 +108,26 @@ homepage: https://github.com/lookout/leafy
107
108
  licenses:
108
109
  - MIT
109
110
  metadata: {}
110
- post_install_message:
111
+ post_install_message:
111
112
  rdoc_options: []
112
113
  require_paths:
113
114
  - lib
114
115
  required_ruby_version: !ruby/object:Gem::Requirement
115
116
  requirements:
116
- - - '>='
117
+ - - ">="
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  requirements:
121
- - - '>='
122
+ - - ">="
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements:
125
126
  - jar io.dropwizard:dropwizard-logging, 0.8.0-rc5, [ joda-time:joda-time ]
126
127
  - jar io.dropwizard:dropwizard-configuration, 0.8.0-rc5, [ org.yaml:snakeyaml ]
127
- rubyforge_project:
128
+ rubyforge_project:
128
129
  rubygems_version: 2.4.5
129
- signing_key:
130
+ signing_key:
130
131
  specification_version: 4
131
132
  summary: adding logback to leafy
132
133
  test_files: []
133
- has_rdoc: