leafy-health 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +34 -4
- data/.travis.yml +19 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -5
- data/README.md +10 -116
- data/examples/datadog/.gitignore +2 -0
- data/examples/datadog/Gemfile +12 -0
- data/examples/datadog/Mavenfile +22 -0
- data/examples/datadog/README.md +16 -0
- data/examples/datadog/lib/java_gauge.rb +20 -0
- data/examples/datadog/lib/metrics.rb +18 -0
- data/examples/datadog/lib/ruby_gauge.rb +19 -0
- data/examples/hellowarld/.gitignore +3 -0
- data/examples/hellowarld/Gemfile +15 -0
- data/examples/hellowarld/Mavenfile +162 -0
- data/examples/hellowarld/README.md +44 -0
- data/examples/hellowarld/Rakefile +13 -0
- data/examples/hellowarld/WEB-INF/web.xml +31 -0
- data/examples/hellowarld/app/hellowarld.rb +55 -0
- data/examples/hellowarld/app/views/person.erb +52 -0
- data/examples/hellowarld/config.ru +12 -0
- data/leafy-complete.gemspec +22 -0
- data/leafy-health/.gitignore +4 -0
- data/leafy-health/Gemfile +7 -0
- data/leafy-health/LICENSE +22 -0
- data/leafy-health/README.md +123 -0
- data/{Rakefile → leafy-health/Rakefile} +0 -0
- data/{leafy-health.gemspec → leafy-health/leafy-health.gemspec} +0 -0
- data/{lib → leafy-health/lib}/leafy-health.rb +0 -0
- data/{lib → leafy-health/lib}/leafy-health_jars.rb +0 -0
- data/{lib → leafy-health/lib}/leafy/health.rb +0 -0
- data/{lib → leafy-health/lib}/leafy/health/health_check.rb +0 -0
- data/{lib → leafy-health/lib}/leafy/health/registry.rb +0 -0
- data/{lib → leafy-health/lib}/leafy/health/version.rb +1 -1
- data/{spec → leafy-health/spec}/registry_spec.rb +0 -0
- data/{spec → leafy-health/spec}/setup.rb +0 -0
- data/leafy-logger/.gitignore +5 -0
- data/leafy-logger/Gemfile +9 -0
- data/leafy-logger/LICENSE +22 -0
- data/leafy-logger/README.md +174 -0
- data/leafy-logger/Rakefile +14 -0
- data/leafy-logger/leafy-logger.gemspec +32 -0
- data/leafy-logger/lib/leafy-logger.rb +1 -0
- data/leafy-logger/lib/leafy-logger_jars.rb +33 -0
- data/leafy-logger/lib/leafy/logger.rb +1 -0
- data/leafy-logger/lib/leafy/logger/appender_factories.rb +89 -0
- data/leafy-logger/lib/leafy/logger/factory.rb +141 -0
- data/leafy-logger/lib/leafy/logger/version.rb +6 -0
- data/leafy-logger/spec/appender_factories_spec.rb +147 -0
- data/leafy-logger/spec/factory_spec.rb +176 -0
- data/leafy-logger/spec/logging.yml +16 -0
- data/leafy-logger/spec/setup.rb +2 -0
- data/leafy-metrics/.gitignore +5 -0
- data/leafy-metrics/Gemfile +7 -0
- data/leafy-metrics/LICENSE +22 -0
- data/leafy-metrics/README.md +221 -0
- data/leafy-metrics/Rakefile +14 -0
- data/leafy-metrics/leafy-metrics.gemspec +29 -0
- data/leafy-metrics/lib/leafy-metrics.rb +2 -0
- data/leafy-metrics/lib/leafy-metrics_jars.rb +5 -0
- data/leafy-metrics/lib/leafy/metrics.rb +2 -0
- data/leafy-metrics/lib/leafy/metrics/console_reporter.rb +32 -0
- data/leafy-metrics/lib/leafy/metrics/csv_reporter.rb +26 -0
- data/leafy-metrics/lib/leafy/metrics/graphite/graphite.rb +28 -0
- data/leafy-metrics/lib/leafy/metrics/graphite/graphite_reporter.rb +43 -0
- data/leafy-metrics/lib/leafy/metrics/registry.rb +108 -0
- data/leafy-metrics/lib/leafy/metrics/reporter.rb +51 -0
- data/leafy-metrics/lib/leafy/metrics/version.rb +6 -0
- data/leafy-metrics/spec/console_reporter_spec.rb +72 -0
- data/leafy-metrics/spec/csv_reporter_spec.rb +75 -0
- data/leafy-metrics/spec/graphite_reporter_spec.rb +72 -0
- data/leafy-metrics/spec/graphite_spec.rb +23 -0
- data/leafy-metrics/spec/registry_spec.rb +106 -0
- data/leafy-metrics/spec/setup.rb +10 -0
- data/leafy-rack/.gitignore +4 -0
- data/leafy-rack/Gemfile +10 -0
- data/leafy-rack/LICENSE +22 -0
- data/leafy-rack/README.md +155 -0
- data/leafy-rack/Rakefile +14 -0
- data/leafy-rack/leafy-rack.gemspec +29 -0
- data/leafy-rack/lib/leafy-rack.rb +1 -0
- data/leafy-rack/lib/leafy-rack_jars.rb +10 -0
- data/leafy-rack/lib/leafy/instrumented/basic_instrumented.rb +38 -0
- data/leafy-rack/lib/leafy/instrumented/instrumented.rb +27 -0
- data/leafy-rack/lib/leafy/json/health_writer.rb +15 -0
- data/leafy-rack/lib/leafy/json/json_writer.rb +33 -0
- data/leafy-rack/lib/leafy/json/metrics_writer.rb +22 -0
- data/leafy-rack/lib/leafy/rack.rb +1 -0
- data/leafy-rack/lib/leafy/rack/admin.rb +73 -0
- data/leafy-rack/lib/leafy/rack/health.rb +43 -0
- data/leafy-rack/lib/leafy/rack/instrumented.rb +20 -0
- data/leafy-rack/lib/leafy/rack/metrics.rb +35 -0
- data/leafy-rack/lib/leafy/rack/ping.rb +29 -0
- data/leafy-rack/lib/leafy/rack/thread_dump.rb +56 -0
- data/leafy-rack/lib/leafy/rack/version.rb +6 -0
- data/leafy-rack/spec/admin_rack_spec.rb +141 -0
- data/leafy-rack/spec/basic_instrumented_spec.rb +31 -0
- data/leafy-rack/spec/health_rack_spec.rb +136 -0
- data/leafy-rack/spec/health_writer_spec.rb +47 -0
- data/leafy-rack/spec/instrumented_rack_spec.rb +37 -0
- data/leafy-rack/spec/instrumented_spec.rb +36 -0
- data/leafy-rack/spec/metrics_rack_spec.rb +110 -0
- data/leafy-rack/spec/metrics_writer_spec.rb +55 -0
- data/leafy-rack/spec/ping_rack_spec.rb +63 -0
- data/leafy-rack/spec/setup.rb +3 -0
- data/leafy-rack/spec/thread_dump_spec.rb +59 -0
- metadata +106 -12
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Lookout
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# Leafy-Logger
|
2
|
+
|
3
|
+
## installation
|
4
|
+
|
5
|
+
via rubygems
|
6
|
+
```
|
7
|
+
gem install leafy-logger
|
8
|
+
```
|
9
|
+
or add to your Gemfile
|
10
|
+
```
|
11
|
+
gem 'leafy-logger
|
12
|
+
```
|
13
|
+
|
14
|
+
installing the gem also takes care of the jar dependencies with jruby-1.7.16+
|
15
|
+
|
16
|
+
## usage
|
17
|
+
|
18
|
+
default configuration
|
19
|
+
```
|
20
|
+
require 'leafy/logger/factory'
|
21
|
+
require 'leafy/metrics/registry'
|
22
|
+
|
23
|
+
f = Leafy::Logger::Factory.new
|
24
|
+
f.configure( Leafy::Metrics::Registry.new, 'application' )
|
25
|
+
|
26
|
+
l = Leafy::Logger::Factory.get_logger 'my.app'
|
27
|
+
```
|
28
|
+
|
29
|
+
the configure will setup the (default) appenders and register the metrics.
|
30
|
+
|
31
|
+
there are more configurations for the logger Factory
|
32
|
+
```
|
33
|
+
require 'leafy/logger/appender_factories'
|
34
|
+
|
35
|
+
f.level = 'INFO'
|
36
|
+
f.loggers 'my.app' => 'WARN', 'my' => 'DEBUG'
|
37
|
+
f.appenders( Leafy::Logger::ConsoleAppenderFactory.new,
|
38
|
+
Leafy::Logger::FileAppenderFactory.new('log/my.log' ) )
|
39
|
+
f[ 'my.db' ] = 'INFO'
|
40
|
+
```
|
41
|
+
|
42
|
+
after the logger factory was configured once, any change of the log levels will result in a reconfiguration.
|
43
|
+
|
44
|
+
## appender factories
|
45
|
+
|
46
|
+
all appender factories have common set of attributes:
|
47
|
+
```
|
48
|
+
appender = Leafy::Logger::ConsoleAppenderFactory.new do
|
49
|
+
# :off, :trace, :debug, :info, :warn, :error, :all
|
50
|
+
self.threshold = :debug # default :all
|
51
|
+
self.log_format = "%-5p [%d{ISO8601,UTC}] %c: %m%n%ex"
|
52
|
+
self.queue_size = 1024 # default 256
|
53
|
+
# means nothing gets discarded
|
54
|
+
self.discarding_threshold = 0 # default -1
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
### console appender factory
|
59
|
+
|
60
|
+
```
|
61
|
+
appender = Leafy::Logger::ConsoleAppenderFactory.new do
|
62
|
+
self.target 'STDOUT' # default is 'STDERR'
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### syslog appender factory
|
67
|
+
|
68
|
+
```
|
69
|
+
appender = Leafy::Logger::SyslogAppenderFactory.new do
|
70
|
+
self.host = '127.0.0.1' # default localhost
|
71
|
+
self.port = 514 # default 514
|
72
|
+
self.include_stack_trace = false # default true
|
73
|
+
# see Leafy::Logger::SyslogAppenderFactory.all_facilities
|
74
|
+
self.facility = :auth # default :local0
|
75
|
+
self.stack_trace_prefix = '__' # default '!'
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
### file appender factory
|
80
|
+
|
81
|
+
without archived files
|
82
|
+
|
83
|
+
```
|
84
|
+
appender = Leafy::Logger::SyslogAppenderFactory.new( 'logs/app.log' )
|
85
|
+
```
|
86
|
+
|
87
|
+
or
|
88
|
+
|
89
|
+
```
|
90
|
+
appender = Leafy::Logger::SyslogAppenderFactory.new do
|
91
|
+
self.current_log_filename = 'logs/app.log'
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
with archived files
|
96
|
+
|
97
|
+
```
|
98
|
+
appender = Leafy::Logger::SyslogAppenderFactory.new do
|
99
|
+
self.current_log_filename = 'logs/app.log'
|
100
|
+
self.archive = true # default true
|
101
|
+
# files ending with .gz or .zip will packed respectively
|
102
|
+
self.archived_log_filename_pattern = 'logs/app-%d.log'
|
103
|
+
self.archived_file_count = 10 # default 5
|
104
|
+
end
|
105
|
+
```
|
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
|
+
|
159
|
+
## developement
|
160
|
+
|
161
|
+
get all the gems and jars in place
|
162
|
+
|
163
|
+
gem install jar-dependencies --development
|
164
|
+
bundle install
|
165
|
+
|
166
|
+
please make sure you are using jar-dependencies >= 0.1.8 !
|
167
|
+
|
168
|
+
for running all specs
|
169
|
+
|
170
|
+
rake
|
171
|
+
|
172
|
+
or a single one
|
173
|
+
|
174
|
+
rspec spec/reporter_spec.rb
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#-*- mode: ruby -*-
|
2
|
+
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
RSpec::Core::RakeTask.new
|
5
|
+
|
6
|
+
require "yard"
|
7
|
+
YARD::Rake::YardocTask.new do |t|
|
8
|
+
t.files = ['lib/**/*.rb']
|
9
|
+
t.options += ["--title", "Leafy Rack Middleware"]
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => [ :spec ]
|
13
|
+
|
14
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#-*- mode: ruby -*-
|
2
|
+
|
3
|
+
require File.expand_path( '../lib/leafy/logger/version', __FILE__ )
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'leafy-logger'
|
7
|
+
s.version = Leafy::Logger::VERSION
|
8
|
+
s.author = 'christian meier'
|
9
|
+
s.email = [ 'christian.meier@lookout.com' ]
|
10
|
+
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.summary = %q(adding logback to leafy)
|
13
|
+
s.homepage = 'https://github.com/lookout/leafy'
|
14
|
+
s.description = %q(adding logback to leafy with yaml configuration and bridges to log4j and jul)
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
|
18
|
+
# exclude the dependencies which come with jruby itself
|
19
|
+
# TODO needs something in jar-dependencies since those jruby dependencies can
|
20
|
+
# be different from version to version
|
21
|
+
|
22
|
+
s.requirements << 'jar io.dropwizard:dropwizard-logging, 0.8.0-rc5, [ joda-time:joda-time ]'
|
23
|
+
s.requirements << 'jar io.dropwizard:dropwizard-configuration, 0.8.0-rc5, [ org.yaml:snakeyaml ]'
|
24
|
+
|
25
|
+
s.add_runtime_dependency 'jar-dependencies', '~> 0.1.8'
|
26
|
+
s.add_runtime_dependency 'leafy-metrics', "~> #{Leafy::Rack::VERSION}"
|
27
|
+
s.add_development_dependency 'rspec', '~> 3.1.0'
|
28
|
+
s.add_development_dependency 'yard', '~> 0.8.7'
|
29
|
+
s.add_development_dependency 'rake', '~> 10.2'
|
30
|
+
end
|
31
|
+
|
32
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'leafy-logger_jars'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# this is a generated file, to avoid over-writing it just delete this comment
|
2
|
+
require 'jar_dependencies'
|
3
|
+
|
4
|
+
require_jar( 'org.slf4j', 'log4j-over-slf4j', '1.7.10' )
|
5
|
+
require_jar( 'com.google.guava', 'guava', '18.0' )
|
6
|
+
require_jar( 'org.slf4j', 'jul-to-slf4j', '1.7.10' )
|
7
|
+
require_jar( 'io.dropwizard', 'dropwizard-logging', '0.8.0-rc5' )
|
8
|
+
require_jar( 'org.slf4j', 'jcl-over-slf4j', '1.7.10' )
|
9
|
+
require_jar( 'org.jboss.logging', 'jboss-logging', '3.1.3.GA' )
|
10
|
+
require_jar( 'io.dropwizard', 'dropwizard-util', '0.8.0-rc5' )
|
11
|
+
require_jar( 'com.fasterxml.jackson.datatype', 'jackson-datatype-jdk7', '2.5.1' )
|
12
|
+
require_jar( 'org.apache.commons', 'commons-lang3', '3.3.2' )
|
13
|
+
require_jar( 'javax.validation', 'validation-api', '1.1.0.Final' )
|
14
|
+
require_jar( 'com.fasterxml.jackson.datatype', 'jackson-datatype-joda', '2.5.1' )
|
15
|
+
require_jar( 'com.fasterxml', 'classmate', '1.0.0' )
|
16
|
+
require_jar( 'org.hibernate', 'hibernate-validator', '5.1.3.Final' )
|
17
|
+
require_jar( 'org.eclipse.jetty', 'jetty-util', '9.2.9.v20150224' )
|
18
|
+
require_jar( 'io.dropwizard', 'dropwizard-configuration', '0.8.0-rc5' )
|
19
|
+
require_jar( 'com.fasterxml.jackson.datatype', 'jackson-datatype-guava', '2.5.1' )
|
20
|
+
require_jar( 'io.dropwizard', 'dropwizard-jackson', '0.8.0-rc5' )
|
21
|
+
require_jar( 'com.fasterxml.jackson.dataformat', 'jackson-dataformat-yaml', '2.5.1' )
|
22
|
+
require_jar( 'org.glassfish', 'javax.el', '3.0.0' )
|
23
|
+
require_jar( 'com.fasterxml.jackson.core', 'jackson-databind', '2.5.1' )
|
24
|
+
require_jar( 'ch.qos.logback', 'logback-classic', '1.1.2' )
|
25
|
+
require_jar( 'com.google.code.findbugs', 'jsr305', '3.0.0' )
|
26
|
+
require_jar( 'com.fasterxml.jackson.core', 'jackson-core', '2.5.1' )
|
27
|
+
require_jar( 'io.dropwizard.metrics', 'metrics-logback', '3.1.0' )
|
28
|
+
require_jar( 'io.dropwizard', 'dropwizard-validation', '0.8.0-rc5' )
|
29
|
+
require_jar( 'org.slf4j', 'slf4j-api', '1.7.10' )
|
30
|
+
require_jar( 'ch.qos.logback', 'logback-core', '1.1.2' )
|
31
|
+
require_jar( 'com.fasterxml.jackson.module', 'jackson-module-afterburner', '2.5.1' )
|
32
|
+
require_jar( 'com.fasterxml.jackson.core', 'jackson-annotations', '2.5.0' )
|
33
|
+
require_jar( 'io.dropwizard.metrics', 'metrics-core', '3.1.0' )
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'leafy-logger_jars'
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'leafy/logger'
|
2
|
+
module Leafy
|
3
|
+
module Logger
|
4
|
+
module AppenderFactory
|
5
|
+
|
6
|
+
def threshold
|
7
|
+
super.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def threshold= t
|
11
|
+
super Java::ChQosLogbackClassic::Level.const_get( t.to_s.upcase )
|
12
|
+
end
|
13
|
+
|
14
|
+
def attributes
|
15
|
+
self.methods.select { |m| m.to_s =~ /^set_/ }.collect { |m| m.to_s.sub( /^set_/, '' ) }
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def new( *args, &block )
|
20
|
+
if block
|
21
|
+
f = new( *args )
|
22
|
+
f.instance_eval( &block )
|
23
|
+
f
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Java::IoDropwizardLogging::FileAppenderFactory
|
32
|
+
|
33
|
+
include AppenderFactory
|
34
|
+
extend AppenderFactory::ClassMethods
|
35
|
+
|
36
|
+
def initialize( file = nil )
|
37
|
+
super()
|
38
|
+
if file
|
39
|
+
self.current_log_filename = file
|
40
|
+
self.archive = false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
FileAppenderFactory = Java::IoDropwizardLogging::FileAppenderFactory
|
45
|
+
|
46
|
+
class Java::IoDropwizardLogging::ConsoleAppenderFactory
|
47
|
+
|
48
|
+
include AppenderFactory
|
49
|
+
extend AppenderFactory::ClassMethods
|
50
|
+
|
51
|
+
alias :_target :target
|
52
|
+
def target( arg = nil )
|
53
|
+
if arg
|
54
|
+
self.target = arg
|
55
|
+
else
|
56
|
+
_target.to_s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
alias :_target= :target=
|
61
|
+
def target= t
|
62
|
+
self._target = Java::IoDropwizardLogging::ConsoleAppenderFactory::ConsoleStream.value_of( t.to_s.upcase )
|
63
|
+
end
|
64
|
+
end
|
65
|
+
ConsoleAppenderFactory = Java::IoDropwizardLogging::ConsoleAppenderFactory
|
66
|
+
|
67
|
+
|
68
|
+
class Java::IoDropwizardLogging::SyslogAppenderFactory
|
69
|
+
|
70
|
+
include AppenderFactory
|
71
|
+
extend AppenderFactory::ClassMethods
|
72
|
+
|
73
|
+
def self.all_facilities
|
74
|
+
Java::IoDropwizardLogging::SyslogAppenderFactory::Facility.values.collect { |f| f.to_s }
|
75
|
+
end
|
76
|
+
|
77
|
+
alias :_facility :facility
|
78
|
+
def facility
|
79
|
+
_facility.to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
alias :_facility= :facility=
|
83
|
+
def facility= t
|
84
|
+
self._facility = Java::IoDropwizardLogging::SyslogAppenderFactory::Facility.value_of( t.to_s.upcase )
|
85
|
+
end
|
86
|
+
end
|
87
|
+
SyslogAppenderFactory = Java::IoDropwizardLogging::SyslogAppenderFactory
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'leafy/logger'
|
2
|
+
require 'leafy/logger/appender_factories'
|
3
|
+
require 'yaml'
|
4
|
+
require 'stringio'
|
5
|
+
require 'jruby/synchronized'
|
6
|
+
|
7
|
+
module Leafy
|
8
|
+
module Logger
|
9
|
+
class Factory
|
10
|
+
include JRuby::Synchronized
|
11
|
+
|
12
|
+
class HashSourceProvider
|
13
|
+
include Java::IoDropwizardConfiguration::ConfigurationSourceProvider
|
14
|
+
|
15
|
+
def initialize( config )
|
16
|
+
@config = config
|
17
|
+
end
|
18
|
+
|
19
|
+
def open(path)
|
20
|
+
StringIO.new( @config.to_yaml ).to_inputstream
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_logger( name )
|
25
|
+
org.slf4j.LoggerFactory.get_logger name
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.bootstrap
|
29
|
+
Java::IoDropwizardLogging::LoggingFactory.bootstrap
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.configurator
|
33
|
+
objectMapper = Java::IoDropwizardJackson::Jackson.newObjectMapper
|
34
|
+
validator = javax.validation.Validation.buildDefaultValidatorFactory.validator
|
35
|
+
Java::IoDropwizardConfiguration::ConfigurationFactory.new( Java::IoDropwizardLogging::LoggingFactory.java_class, validator, objectMapper, "" )
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.new_from_options( options )
|
39
|
+
new( configurator.build( HashSourceProvider.new( options ), 'dummy') )
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.new_from_yaml( yamlfile )
|
43
|
+
raise "no such file #{yamlfile}" unless File.exists?( yamlfile )
|
44
|
+
new( configurator.build( java.io.File.new( yamlfile ) ) )
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize( factory = nil )
|
48
|
+
@factory = factory || Java::IoDropwizardLogging::LoggingFactory.new
|
49
|
+
end
|
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
|
+
|
67
|
+
def level args = nil
|
68
|
+
if args
|
69
|
+
self.level = args
|
70
|
+
else
|
71
|
+
@factory.level.to_s
|
72
|
+
end
|
73
|
+
end
|
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
|
+
|
81
|
+
def level= level
|
82
|
+
l = level.to_s.upcase
|
83
|
+
@factory.level = Java::ChQosLogbackClassic::Level.const_get( l )
|
84
|
+
reconfigure
|
85
|
+
end
|
86
|
+
|
87
|
+
def appenders( *args )
|
88
|
+
if args.size > 0
|
89
|
+
self.appenders = args
|
90
|
+
else
|
91
|
+
@factory.appenders.to_a
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def appenders= args
|
96
|
+
@factory.appenders = args
|
97
|
+
reconfigure
|
98
|
+
end
|
99
|
+
|
100
|
+
def loggers( map = nil )
|
101
|
+
if map
|
102
|
+
self.loggers = map
|
103
|
+
else
|
104
|
+
Hash[ @factory.loggers.collect {|k,v| [k, v.to_s ] } ]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def []=( name, level )
|
109
|
+
m = @factory.loggers.to_hash
|
110
|
+
m[ name ] = level
|
111
|
+
self.loggers = m
|
112
|
+
end
|
113
|
+
|
114
|
+
def loggers_set map
|
115
|
+
m = {}
|
116
|
+
map.each { |k,v| m[k] = Java::ChQosLogbackClassic::Level.const_get( v.to_s.upcase ) }
|
117
|
+
@factory.loggers = m
|
118
|
+
end
|
119
|
+
private :loggers_set
|
120
|
+
|
121
|
+
def loggers= map
|
122
|
+
loggers_set( map )
|
123
|
+
reconfigure
|
124
|
+
end
|
125
|
+
|
126
|
+
def configure( metrics, name )
|
127
|
+
@metrics = metrics
|
128
|
+
@name = name
|
129
|
+
reconfigure
|
130
|
+
end
|
131
|
+
|
132
|
+
def reconfigure
|
133
|
+
@factory.configure( @metrics.metrics, @name ) if @metrics
|
134
|
+
end
|
135
|
+
|
136
|
+
def stop
|
137
|
+
@factory.stop
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|