Permalink
Browse files

check for deployment descriptor jruby-rack.logging parameter

when configuring web-app logging (fixes #76)
  • Loading branch information...
1 parent ad4f8a0 commit 4c11ab93cfb80636a44b288724fbec1f51623187 @kares kares committed Jul 24, 2012
Showing with 33 additions and 2 deletions.
  1. +6 −2 lib/trinidad/logging.rb
  2. +27 −0 spec/trinidad/logging_spec.rb
View
@@ -52,14 +52,14 @@ def self.configure!(log_level = nil)
def self.configure_web_app(web_app, context)
param_name, param_value = 'jruby.rack.logging', 'JUL'
# 1. delegate (jruby-rack) servlet log to JUL
- if set_value = context.find_parameter(param_name)
+ if set_value = web_app_context_param(web_app, context, param_name)
return nil if set_value.upcase != param_value
else
context.add_parameter(param_name, param_value)
end
# 2. use Tomcat's JUL logger name (unless set) :
param_name = 'jruby.rack.logging.name'
- unless logger_name = context.find_parameter(param_name)
+ unless logger_name = web_app_context_param(web_app, context, param_name)
# for a context path e.g. '/foo' most likely smt of the following :
# org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/foo]
context.add_parameter(param_name, logger_name = context.send(:logName))
@@ -118,6 +118,10 @@ def self.adjust_tomcat_loggers
logger.level = JUL::Level::WARNING if logger
end
+ def self.web_app_context_param(web_app, context, name)
+ context.find_parameter(name) || web_app.web_xml_context_param(name)
+ end
+
# we'd achieve logging to a production.log file while rotating it (daily)
class FileHandler < Java::OrgApacheJuli::FileHandler # :nodoc
@@ -210,6 +210,33 @@
output.toString.should == ''
end
+
+ it "does not configure logger if descriptor specified non JUL logging" do
+ FileUtils.touch custom_web_xml = "#{MOCK_WEB_APP_DIR}/config/logging-test.web.xml"
+ begin
+ create_config_file custom_web_xml, '' +
+ '<?xml version="1.0" encoding="UTF-8"?>' +
+ '<web-app>' +
+ ' <context-param>' +
+ ' <param-name>jruby.rack.logging</param-name>' +
+ ' <param-value>stdout</param-value>' +
+ ' </context-param>' +
+ '</web-app>'
+ web_app = Trinidad::WebApp.create({}, {
+ :context_path => '/',
+ :web_app_dir => MOCK_WEB_APP_DIR,
+ :default_web_xml => 'config/logging-test.web.xml',
+ :log => 'ALL'
+ })
+ context = create_mock_web_app_context web_app.context_path
+ context.setDefaultWebXml web_app.default_deployment_descriptor
+
+ outcome = Trinidad::Logging.configure_web_app(web_app, context)
+ outcome.should be nil
+ ensure
+ FileUtils.rm custom_web_xml
+ end
+ end
it "accepts configured logger name (from descriptor)", :integration => true do
FileUtils.touch custom_web_xml = "#{MOCK_WEB_APP_DIR}/config/logging-test.web.xml"

0 comments on commit 4c11ab9

Please sign in to comment.