log4jruby 1.0.0.rc1-java → 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +37 -0
- data/{README.rdoc → README.md} +38 -35
- data/lib/log4jruby.rb +7 -5
- data/lib/log4jruby/logger.rb +86 -62
- data/lib/log4jruby/support/bootstrap.rb +18 -0
- data/lib/log4jruby/support/log4j_args.rb +42 -0
- data/lib/log4jruby/version.rb +1 -1
- metadata +14 -16
- data/History.txt +0 -6
- data/lib/log4jruby/log4j_args.rb +0 -40
- data/lib/log4jruby/rails.rb +0 -62
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 123749780219fb12c1e95b794ea13a73c473a785
|
4
|
+
data.tar.gz: c0bfb65f10f261e5343442feb2ac1cc7516bc5ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d96660a9830a4d0dd2197de2c1b98742b1c5964717a0f8647932260697df64cf44f73f09630031317dcb9b4673c2e5f50925b89963160bb8329c156ffb229ff0
|
7
|
+
data.tar.gz: 29ad95b74510eb71a4c37e0e9a510bdfa778f4fa89cfa1980810901704036ec1419dc1f56d0d326a3a5ade619828cc98d025d775d8443e061fba74e21545952b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# log4jruby Changelog
|
2
|
+
|
3
|
+
## v2.0.0
|
4
|
+
|
5
|
+
* Documentation additions, corrections.
|
6
|
+
|
7
|
+
## v2.0.0.rc3
|
8
|
+
|
9
|
+
* Add Logger#silence for ActiveSupport::Logger compatibility - https://github.com/lenny/log4jruby/pull/11
|
10
|
+
|
11
|
+
## v2.0.0.rc2
|
12
|
+
|
13
|
+
* Internal implementation changes - https://github.com/lenny/log4jruby/pull/8
|
14
|
+
|
15
|
+
## v2.0.0.rc1
|
16
|
+
|
17
|
+
* ```Log4jruby::Rails``` has been removed - Rails apps seem better off configuring
|
18
|
+
logging using standard/vanilla means to more easily facilitate usage of TaggedLogging, etc..
|
19
|
+
```
|
20
|
+
|
21
|
+
e.g.
|
22
|
+
config.logger = ActiveSupport::TaggedLogging.new(Log4jruby::Logger.get('appname'))
|
23
|
+
```
|
24
|
+
* Internal support classes moved to Log4jruby::Support
|
25
|
+
* specs updated to Rspec 3 syntax
|
26
|
+
* Deadlock/thread-safety issues https://github.com/lenny/log4jruby/issues/2
|
27
|
+
* Support for formatters (Rails 4 compatibility - https://github.com/lenny/log4jruby/issues/1)
|
28
|
+
* Performance optimizations (https://github.com/lenny/log4jruby/commit/e9a2a2ac347de38431e243b062602c5055163f2c)
|
29
|
+
|
30
|
+
## v1.0.0 - Same as v1.0.0.rc1
|
31
|
+
|
32
|
+
## v1.0.0.rc1
|
33
|
+
|
34
|
+
* setting level now accepts ::Logger constants and symbols
|
35
|
+
* Logger#level now returns ::Logger constant values instead of Log4j log level classes.
|
36
|
+
Note, you can still get at log4j constants via #log4_logger.level
|
37
|
+
* Logger#level now returns effective log level (i.e. parent logger's level when not explicitly set)
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,24 +1,26 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
|
3
|
+
# Log4jruby
|
2
4
|
|
3
5
|
* https://github.com/lenny/log4jruby
|
4
6
|
|
5
|
-
|
7
|
+
## Description:
|
6
8
|
|
7
9
|
Log4jruby is a thin wrapper around the {Log4j Logger}[http://logging.apache.org/log4j/1.2/apidocs/index.html].
|
8
10
|
It is geared more toward those who are using JRuby to integrate with and build on top of Java code that uses Log4j.
|
9
|
-
The
|
11
|
+
The ```Log4jruby::Logger``` provides an interface much like the standard ruby [Logger](http://ruby-doc.org/core/classes/Logger.html).
|
10
12
|
Logging is configured via traditional Log4j methods.
|
11
13
|
|
12
|
-
The primary use case(i.e
|
14
|
+
The primary use case (i.e., mine) for this library is that you are already up and running with Log4j and now you want
|
13
15
|
to use it for your Ruby code too. There is not much help here for configuration. In our environment, we deploy Rails
|
14
|
-
apps that call and extend Java code into Tomcat as WARs and use a log4j.properties to configure. For the most part,
|
16
|
+
apps that call and extend Java code into Tomcat as WARs and use a log4j.properties to configure. For the most part,
|
15
17
|
all there is to using log4jruby is making sure the log4j jar is <tt>required</tt> and that Log4j is at least minimally
|
16
|
-
configured(e.g
|
18
|
+
configured (e.g., log4j.properties in the CLASSPATH). The examples should give you the idea.
|
17
19
|
|
18
|
-
|
20
|
+
### Features
|
19
21
|
|
20
|
-
* Filename, line number, and method name are available(if tracing is on) to your appender layout via {MDC}[http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/MDC.html].
|
21
|
-
* Exceptions can be logged directly and are output with backtraces. Java Exceptions(i.e
|
22
|
+
* Filename, line number, and method name are available (if tracing is on) to your appender layout via {MDC}[http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/MDC.html].
|
23
|
+
* Exceptions can be logged directly and are output with backtraces. Java Exceptions (i.e., NativeExceptions)
|
22
24
|
are logged with full java backtrace(including nested exceptions).
|
23
25
|
* Logging config for your ruby code can be added to your existing configuration. Ruby logger names are mapped to dot separated names prefixed with <tt>.jruby</tt>
|
24
26
|
|
@@ -29,7 +31,26 @@ configured(e.g. log4j.properties in the CLASSPATH). The examples should give you
|
|
29
31
|
log4j.logger.jruby=info,Ruby
|
30
32
|
log4j.logger.jruby.MyClass=debug
|
31
33
|
|
32
|
-
|
34
|
+
### Configuration
|
35
|
+
|
36
|
+
As noted above, configuring log4j is left to the client. **You must load and configure log4j before requiring log4jruby**.
|
37
|
+
There are multiple ways to do so.
|
38
|
+
In our environment, we deploy Rails apps that call and extend Java code to Tomcat as WAR files.
|
39
|
+
We provision our app servers with ```log4j.jar``` and a ```log4j.properties``` file in in ```$TOMCAT_HOME/lib```.
|
40
|
+
You may also addd log4j.jar and path to config file into CLASSPATH via environment variables, JAVA_OPTS, JAVA_OPTS, etc...
|
41
|
+
Or add them into ```$CLASSPATH``` at runtime before loading log4jruby. See [examples/setup.rb](examples/setup.rb).
|
42
|
+
|
43
|
+
Note: If you're using bundler, you can specify ```gem 'log4jruby', require: false``` in your Gemfile to delay loading the gem too early.
|
44
|
+
|
45
|
+
In a Rails application, add the following in ```config/application.rb``` or the appropriate ```config/environments``` file.
|
46
|
+
|
47
|
+
config.logger = ActiveSupport::TaggedLogging.new(Log4jruby::Logger.get('MyApp'))
|
48
|
+
|
49
|
+
or older versions of Rails
|
50
|
+
|
51
|
+
config.logger = Log4jruby::Logger.get('MyApp')
|
52
|
+
|
53
|
+
### Examples
|
33
54
|
|
34
55
|
def foo
|
35
56
|
logger.debug("hello from foo")
|
@@ -47,45 +68,27 @@ configured(e.g. log4j.properties in the CLASSPATH). The examples should give you
|
|
47
68
|
examples/simple.rb:18:in `foo'
|
48
69
|
examples/simple.rb:35:in `(root)'
|
49
70
|
|
50
|
-
See more in
|
51
|
-
|
52
|
-
=== Installation
|
71
|
+
See more in [log4jruby/examples](examples).
|
53
72
|
|
54
|
-
|
55
|
-
|
56
|
-
=== Usage
|
73
|
+
### Usage
|
57
74
|
|
58
75
|
class MyClass
|
59
76
|
enable_logger
|
60
|
-
|
77
|
+
|
61
78
|
class << self
|
62
79
|
def my_class_method
|
63
80
|
logger.info("hello from class method")
|
64
81
|
end
|
65
82
|
end
|
66
|
-
|
83
|
+
|
67
84
|
def my_method
|
68
85
|
logger.info("hello from instance method")
|
69
86
|
end
|
70
87
|
end
|
71
|
-
|
88
|
+
|
72
89
|
INFO jruby.MyModule.A my_class_method:14 - hello from class method
|
73
90
|
INFO jruby.MyModule.A my_method:19 - hello from instance method
|
74
|
-
|
75
|
-
See more in {log4jruby/examples}[http://github.com/lenny/log4jruby/tree/master/examples/].
|
76
|
-
They should be runnable from the source.
|
77
|
-
|
78
|
-
=== Rails
|
79
91
|
|
80
|
-
|
81
|
-
|
82
|
-
require 'log4jruby'
|
83
|
-
config.logger = Log4jruby::Logger.get('MyApp')
|
84
|
-
|
85
|
-
Depending on your runtime environment and how it differs between development and production that may not work for you
|
86
|
-
due to CLASSPATH issues. Alternatively you may add the following to one of your config/initializers/* files.
|
92
|
+
See more in [log4jruby/examples](examples)..
|
93
|
+
They should be runnable from the source.
|
87
94
|
|
88
|
-
require 'log4jruby/rails'
|
89
|
-
Log4jruby::Rails.configure do |c|
|
90
|
-
c.logger_name = 'MyApp'
|
91
|
-
end
|
data/lib/log4jruby.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
require 'log4jruby/logger'
|
2
|
-
require 'log4jruby/logger_for_class'
|
3
|
-
|
4
1
|
module Log4jruby
|
5
|
-
|
2
|
+
module Support
|
3
|
+
end
|
6
4
|
end
|
7
5
|
|
6
|
+
require 'log4jruby/support/bootstrap'
|
7
|
+
require 'log4jruby/logger'
|
8
|
+
require 'log4jruby/logger_for_class'
|
9
|
+
|
8
10
|
Object.class_eval do
|
9
11
|
class << self
|
10
12
|
def enable_logger
|
11
13
|
send(:include, Log4jruby::LoggerForClass)
|
12
14
|
end
|
13
15
|
end
|
14
|
-
end
|
16
|
+
end
|
data/lib/log4jruby/logger.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
require 'log4jruby/log4j_args'
|
1
|
+
require 'log4jruby/support/log4j_args'
|
2
2
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
5
|
module Log4jruby
|
6
|
-
|
6
|
+
|
7
7
|
# Author:: Lenny Marks
|
8
8
|
#
|
9
9
|
# Wrapper around org.apache.log4j.Logger with interface similar to standard ruby Logger.
|
10
10
|
#
|
11
11
|
# * Ruby and Java exceptions are logged with backtraces.
|
12
|
-
# * fileName, lineNumber, methodName available to appender layouts via MDC variables(e.g. %X{lineNumber})
|
12
|
+
# * fileName, lineNumber, methodName available to appender layouts via MDC variables(e.g. %X{lineNumber})
|
13
13
|
class Logger
|
14
|
-
BLANK_CALLER = ['', '', ''] #:nodoc:
|
15
|
-
|
16
14
|
LOG4J_LEVELS = {
|
17
15
|
Java::org.apache.log4j.Level::DEBUG => ::Logger::DEBUG,
|
18
16
|
Java::org.apache.log4j.Level::INFO => ::Logger::INFO,
|
@@ -21,48 +19,47 @@ module Log4jruby
|
|
21
19
|
Java::org.apache.log4j.Level::FATAL => ::Logger::FATAL,
|
22
20
|
}
|
23
21
|
|
24
|
-
# turn tracing on to make fileName, lineNumber, and methodName available to
|
22
|
+
# turn tracing on to make fileName, lineNumber, and methodName available to
|
25
23
|
# appender layout through MDC(ie. %X{fileName} %X{lineNumber} %X{methodName})
|
26
24
|
attr_accessor :tracing
|
27
25
|
|
26
|
+
# ::Logger::Formatter
|
27
|
+
attr_accessor :formatter
|
28
|
+
|
28
29
|
class << self
|
29
|
-
def logger_mapping
|
30
|
-
@logger_mapping ||= {}
|
31
|
-
end
|
32
|
-
|
33
30
|
# get Logger for name
|
34
31
|
def[](name)
|
35
32
|
name = name.nil? ? 'jruby' : "jruby.#{name.gsub('::', '.')}"
|
36
|
-
|
37
33
|
log4j = Java::org.apache.log4j.Logger.getLogger(name)
|
38
|
-
|
39
|
-
|
40
|
-
unless log4jruby
|
41
|
-
log4jruby = new(log4j)
|
42
|
-
end
|
43
|
-
|
44
|
-
log4jruby
|
34
|
+
fetch_logger(log4j)
|
45
35
|
end
|
46
|
-
|
36
|
+
|
47
37
|
# same as [] but accepts attributes
|
48
38
|
def get(name, values = {})
|
49
39
|
logger = self[name]
|
50
40
|
logger.attributes = values
|
51
41
|
logger
|
52
42
|
end
|
53
|
-
|
43
|
+
|
54
44
|
# Return root Logger(i.e. jruby)
|
55
45
|
def root
|
56
46
|
log4j = Java::org.apache.log4j.Logger.getLogger('jruby')
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
47
|
+
fetch_logger(log4j)
|
48
|
+
end
|
49
|
+
|
50
|
+
def reset # :nodoc:
|
51
|
+
Java::org.apache.log4j.LogManager.getCurrentLoggers.each do |l|
|
52
|
+
l.ruby_logger = nil
|
61
53
|
end
|
62
|
-
|
63
|
-
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def fetch_logger(log4j_logger)
|
59
|
+
Java::org.apache.log4j.Logger.getLogger(log4j_logger.getName).ruby_logger
|
60
|
+
end
|
64
61
|
end
|
65
|
-
|
62
|
+
|
66
63
|
def attributes=(values)
|
67
64
|
if values
|
68
65
|
values.each_pair do |k, v|
|
@@ -71,7 +68,7 @@ module Log4jruby
|
|
71
68
|
end
|
72
69
|
end
|
73
70
|
end
|
74
|
-
|
71
|
+
|
75
72
|
# Shortcut for setting log levels. (:debug, :info, :warn, :error, :fatal)
|
76
73
|
def level=(level)
|
77
74
|
@logger.level = case level
|
@@ -89,11 +86,11 @@ module Log4jruby
|
|
89
86
|
raise NotImplementedError
|
90
87
|
end
|
91
88
|
end
|
92
|
-
|
89
|
+
|
93
90
|
def level
|
94
91
|
LOG4J_LEVELS[@logger.effectiveLevel]
|
95
92
|
end
|
96
|
-
|
93
|
+
|
97
94
|
def flush
|
98
95
|
#rails compatability
|
99
96
|
end
|
@@ -136,65 +133,88 @@ module Log4jruby
|
|
136
133
|
def log4j_logger
|
137
134
|
@logger
|
138
135
|
end
|
139
|
-
|
136
|
+
|
140
137
|
def debug?
|
141
138
|
@logger.isEnabledFor(Java::org.apache.log4j.Priority::DEBUG)
|
142
139
|
end
|
143
|
-
|
140
|
+
|
144
141
|
def info?
|
145
142
|
@logger.isEnabledFor(Java::org.apache.log4j.Priority::INFO)
|
146
143
|
end
|
147
|
-
|
144
|
+
|
148
145
|
def warn?
|
149
146
|
@logger.isEnabledFor(Java::org.apache.log4j.Priority::WARN)
|
150
147
|
end
|
151
|
-
|
148
|
+
|
152
149
|
def tracing?
|
153
|
-
if
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
150
|
+
return @cached_tracing if defined?(@cached_tracing)
|
151
|
+
@cached_tracing = begin
|
152
|
+
if tracing.nil? && self != Logger.root
|
153
|
+
parent.tracing?
|
154
|
+
else
|
155
|
+
tracing == true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def effective_formatter
|
161
|
+
return @formatter if defined?(@formatter)
|
162
|
+
@formatter = begin
|
163
|
+
if @formatter.nil? && self != Logger.root
|
164
|
+
parent.formatter
|
165
|
+
else
|
166
|
+
@formatter
|
158
167
|
end
|
159
|
-
else
|
160
|
-
tracing == true
|
161
168
|
end
|
162
169
|
end
|
163
|
-
|
170
|
+
|
164
171
|
def parent
|
165
|
-
|
172
|
+
fetch_logger(log4j_logger.parent)
|
166
173
|
end
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
def
|
171
|
-
|
174
|
+
|
175
|
+
# Compatibility with ActiveSupport::Logger
|
176
|
+
# needed to use a Log4jruby::Logger as an ActiveRecord::Base.logger
|
177
|
+
def silence(temporary_level = ::Logger::ERROR)
|
178
|
+
begin
|
179
|
+
old_logger_level, self.level = level, temporary_level
|
180
|
+
yield self
|
181
|
+
ensure
|
182
|
+
self.level = old_logger_level
|
183
|
+
end
|
172
184
|
end
|
173
185
|
|
186
|
+
private
|
187
|
+
|
174
188
|
def initialize(logger) # :nodoc:
|
175
189
|
@logger = logger
|
176
|
-
Logger.logger_mapping[@logger] = self
|
177
190
|
end
|
178
|
-
|
191
|
+
|
179
192
|
def with_context # :nodoc:
|
180
|
-
file_line_method =
|
193
|
+
file_line_method = parse_caller(caller(3).first)
|
181
194
|
|
182
|
-
mdc.put(
|
183
|
-
mdc.put(
|
184
|
-
mdc.put(
|
195
|
+
mdc.put('fileName', file_line_method[0])
|
196
|
+
mdc.put('lineNumber', file_line_method[1])
|
197
|
+
mdc.put('methodName', file_line_method[2].to_s)
|
185
198
|
|
186
199
|
begin
|
187
200
|
yield
|
188
201
|
ensure
|
189
|
-
mdc.remove(
|
190
|
-
mdc.remove(
|
191
|
-
mdc.remove(
|
202
|
+
mdc.remove('fileName')
|
203
|
+
mdc.remove('lineNumber')
|
204
|
+
mdc.remove('methodName')
|
192
205
|
end
|
193
206
|
end
|
194
207
|
|
195
208
|
def send_to_log4j(level, object, error, &block)
|
196
|
-
msg, throwable = Log4jArgs.convert(object, error, &block)
|
197
|
-
|
209
|
+
msg, throwable = Support::Log4jArgs.convert(object, error, &block)
|
210
|
+
if (f = effective_formatter)
|
211
|
+
msg = f.call(level, Time.now, @logger.getName, msg)
|
212
|
+
end
|
213
|
+
if tracing?
|
214
|
+
with_context do
|
215
|
+
@logger.send(level, msg, throwable)
|
216
|
+
end
|
217
|
+
else
|
198
218
|
@logger.send(level, msg, throwable)
|
199
219
|
end
|
200
220
|
end
|
@@ -202,10 +222,14 @@ module Log4jruby
|
|
202
222
|
def parse_caller(at) # :nodoc:
|
203
223
|
at.match(/^(.+?):(\d+)(?::in `(.*)')?/).captures
|
204
224
|
end
|
205
|
-
|
225
|
+
|
206
226
|
def mdc
|
207
|
-
Java::org.apache.log4j.MDC
|
227
|
+
Java::org.apache.log4j.MDC
|
228
|
+
end
|
229
|
+
|
230
|
+
def fetch_logger(log4j_logger)
|
231
|
+
self.class.send(:fetch_logger, log4j_logger)
|
208
232
|
end
|
209
|
-
|
210
233
|
end
|
211
234
|
end
|
235
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
Java::org.apache.log4j.Logger.class_eval do
|
4
|
+
attr_accessor :ruby_logger
|
5
|
+
@ruby_logger_lock = Mutex.new
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def ruby_logger_lock
|
9
|
+
@ruby_logger_lock
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def ruby_logger
|
14
|
+
self.class.ruby_logger_lock.synchronize do
|
15
|
+
@ruby_logger ||= Log4jruby::Logger.new(self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Log4jruby
|
2
|
+
module Support
|
3
|
+
class Log4jArgs
|
4
|
+
class << self
|
5
|
+
def convert(object = nil, exception = nil)
|
6
|
+
msg = ''
|
7
|
+
|
8
|
+
if exception
|
9
|
+
msg << object.to_s
|
10
|
+
else
|
11
|
+
exception = block_given? ? yield : object
|
12
|
+
end
|
13
|
+
|
14
|
+
if exception.is_a?(NativeException)
|
15
|
+
append_ruby_error(msg, exception)
|
16
|
+
msg << "\nNativeException:"
|
17
|
+
exception = exception.cause
|
18
|
+
elsif exception.is_a?(::Exception)
|
19
|
+
append_ruby_error(msg, exception)
|
20
|
+
exception = nil
|
21
|
+
elsif !exception.is_a?(java.lang.Throwable)
|
22
|
+
msg << exception.to_s
|
23
|
+
exception = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
[msg, exception]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def append_ruby_error(msg, error)
|
32
|
+
append(msg, "#{error}\n " + error.backtrace.join("\n "))
|
33
|
+
end
|
34
|
+
|
35
|
+
def append(msg, s)
|
36
|
+
msg << "\n#{s}"
|
37
|
+
msg.lstrip!
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/log4jruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log4jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.0.0.rc1
|
4
|
+
version: 2.0.0
|
6
5
|
platform: java
|
7
6
|
authors:
|
8
7
|
- Lenny Marks
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Ruby Logger using Log4j, geared toward those who use JRuby to write Ruby code using/extending Java code. Ruby and Java are configured together using traditional Log4j methods.
|
15
14
|
email:
|
@@ -18,37 +17,36 @@ executables: []
|
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- README.md
|
21
22
|
- lib/log4jruby.rb
|
22
|
-
- lib/log4jruby/log4j_args.rb
|
23
23
|
- lib/log4jruby/logger.rb
|
24
24
|
- lib/log4jruby/logger_for_class.rb
|
25
|
-
- lib/log4jruby/
|
25
|
+
- lib/log4jruby/support/bootstrap.rb
|
26
|
+
- lib/log4jruby/support/log4j_args.rb
|
26
27
|
- lib/log4jruby/version.rb
|
27
|
-
- README.rdoc
|
28
|
-
- History.txt
|
29
28
|
homepage: https://github.com/lenny/log4jruby
|
30
|
-
licenses:
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
31
32
|
post_install_message:
|
32
33
|
rdoc_options: []
|
33
34
|
require_paths:
|
34
35
|
- lib
|
35
36
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
37
|
requirements:
|
37
|
-
- -
|
38
|
+
- - '>='
|
38
39
|
- !ruby/object:Gem::Version
|
39
40
|
version: '0'
|
40
|
-
none: false
|
41
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
none: false
|
45
|
+
version: '0'
|
47
46
|
requirements: []
|
48
47
|
rubyforge_project:
|
49
|
-
rubygems_version:
|
48
|
+
rubygems_version: 2.4.8
|
50
49
|
signing_key:
|
51
|
-
specification_version:
|
50
|
+
specification_version: 4
|
52
51
|
summary: Log4jruby is a thin wrapper around the Log4j Logger. It is geared more toward those who are using JRuby to integrate with and build on top of Java code that uses Log4j. The Log4jruby::Logger provides an interface much like the standard ruby Logger. Your ruby loggers are given a .jruby prefix and can be configured along with the loggers for your Java code.
|
53
52
|
test_files: []
|
54
|
-
...
|
data/History.txt
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
1.0.0.rc1
|
2
|
-
|
3
|
-
* setting level now accepts ::Logger constants and symbols
|
4
|
-
* Logger#level now returns ::Logger constant values instead of Log4j log level classes.
|
5
|
-
Note, you can still get at log4j constants via #log4_logger.level
|
6
|
-
* Logger#level now returns effective log level (i.e. parent logger's level when not explicitly set)
|
data/lib/log4jruby/log4j_args.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module Log4jruby
|
2
|
-
class Log4jArgs
|
3
|
-
class << self
|
4
|
-
def convert(object = nil, exception = nil)
|
5
|
-
msg = ''
|
6
|
-
|
7
|
-
if exception
|
8
|
-
msg << object.to_s
|
9
|
-
else
|
10
|
-
exception = block_given? ? yield : object
|
11
|
-
end
|
12
|
-
|
13
|
-
if exception.is_a?(NativeException)
|
14
|
-
append_ruby_error(msg, exception)
|
15
|
-
msg << "\nNativeException:"
|
16
|
-
exception = exception.cause
|
17
|
-
elsif exception.is_a?(::Exception)
|
18
|
-
append_ruby_error(msg, exception)
|
19
|
-
exception = nil
|
20
|
-
elsif !exception.is_a?(java.lang.Throwable)
|
21
|
-
msg << exception.to_s
|
22
|
-
exception = nil
|
23
|
-
end
|
24
|
-
|
25
|
-
[msg, exception]
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def append_ruby_error(msg, error)
|
31
|
-
append(msg, "#{error}\n " + error.backtrace.join("\n "))
|
32
|
-
end
|
33
|
-
|
34
|
-
def append(msg, s)
|
35
|
-
msg << "\n#{s}"
|
36
|
-
msg.lstrip!
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/log4jruby/rails.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'log4jruby'
|
2
|
-
|
3
|
-
module Log4jruby
|
4
|
-
|
5
|
-
# Configure Rails logging from a config/initializers file
|
6
|
-
#
|
7
|
-
# Setting up log4j using config.logger from within the Rails initialization
|
8
|
-
# process may not be possible if the CLASSPATH has not yet been setup.
|
9
|
-
# This class can be used to configure the logging from within a config/initializers/
|
10
|
-
# file.
|
11
|
-
#
|
12
|
-
# ex.
|
13
|
-
# require 'log4jruby/rails'
|
14
|
-
# Log4jruby::Rails.configure do |c|
|
15
|
-
# c.logger_name = 'MyApp'
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# @attr [String] logger_name Default is 'Rails'
|
19
|
-
# @attr [String] tracing Defaults to false in 'production' or true otherwise
|
20
|
-
#
|
21
|
-
#
|
22
|
-
class Rails
|
23
|
-
attr_accessor :logger_name, :tracing
|
24
|
-
|
25
|
-
def initialize #:nodoc:
|
26
|
-
@logger_name = 'Rails'
|
27
|
-
@tracing = (::Rails.env != 'production')
|
28
|
-
|
29
|
-
yield(self)
|
30
|
-
end
|
31
|
-
|
32
|
-
class << self
|
33
|
-
|
34
|
-
# Sets rails Base loggers(e.g. ActionController::Base, ActiveRecord::Base, etc)
|
35
|
-
#
|
36
|
-
# @yield [config] Block to customize configuration
|
37
|
-
# @yeildparam [Rails] config
|
38
|
-
def configure(&block)
|
39
|
-
config = new(&block)
|
40
|
-
|
41
|
-
Logger.root.tracing = config.tracing
|
42
|
-
|
43
|
-
logger = Log4jruby::Logger.get(config.logger_name)
|
44
|
-
|
45
|
-
set_logger('ActionController', logger)
|
46
|
-
set_logger('ActiveRecord', logger)
|
47
|
-
set_logger('ActiveResource', logger)
|
48
|
-
set_logger('ActionMailer', logger)
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def set_logger(framework, logger)
|
54
|
-
begin
|
55
|
-
Kernel.const_get(framework).const_get('Base').logger = logger
|
56
|
-
rescue
|
57
|
-
logger.info "Skipping logger setup for #{framework}"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|