From c54b4cfb081035e497393820add0dbd8edc12def Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 20 Nov 2001 21:13:47 +0000 Subject: [PATCH] Add servlet context logger during servlet initialization phase. Allow servlet context to be specified at construct time to servlet context logger. git-svn-id: https://samskivert.googlecode.com/svn/trunk@460 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../velocity/DispatcherServlet.java | 6 +++- .../velocity/ServletContextLogger.java | 30 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/velocity/DispatcherServlet.java b/projects/samskivert/src/java/com/samskivert/velocity/DispatcherServlet.java index e7d547f2..8a8c8d66 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/DispatcherServlet.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/DispatcherServlet.java @@ -1,5 +1,5 @@ // -// $Id: DispatcherServlet.java,v 1.11 2001/11/06 20:55:51 mdb Exp $ +// $Id: DispatcherServlet.java,v 1.12 2001/11/20 21:13:47 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -205,6 +205,10 @@ public class DispatcherServlet extends VelocityServlet // wire up our #import directive props.put("userdirective", ImportDirective.class.getName()); + // configure the servlet context logger + props.put(RuntimeSingleton.RUNTIME_LOG_LOGSYSTEM, + new ServletContextLogger(getServletContext())); + // now return our augmented properties return props; } diff --git a/projects/samskivert/src/java/com/samskivert/velocity/ServletContextLogger.java b/projects/samskivert/src/java/com/samskivert/velocity/ServletContextLogger.java index 423639fd..96a0b7c4 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/ServletContextLogger.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/ServletContextLogger.java @@ -1,5 +1,5 @@ // -// $Id: ServletContextLogger.java,v 1.1 2001/11/20 21:08:35 mdb Exp $ +// $Id: ServletContextLogger.java,v 1.2 2001/11/20 21:13:47 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -30,12 +30,34 @@ import org.apache.velocity.runtime.log.LogSystem; */ public class ServletContextLogger implements LogSystem { + /** + * Constructs a servlet context logger that will obtain its servlet + * context reference via {@link RuntimeServices#getApplicationContext} + * when initialized. + */ + public ServletContextLogger () + { + } + + /** + * Constructs a servlet context logger with the supplied servlet + * context. + */ + public ServletContextLogger (ServletContext sctx) + { + _sctx = sctx; + } + // documentation inherited public void init (RuntimeServices rsvc) { - // the web framework was kind enough to slip this into the runtime - // instance when it started up - _sctx = (ServletContext)rsvc.getApplicationContext(); + // if we weren't constructed with a servlet context, try to obtain + // one via the application context + if (_sctx == null) { + _sctx = (ServletContext)rsvc.getApplicationContext(); + } + + // if we still don't have one, complain if (_sctx == null) { rsvc.warn("ServletContextLogger: servlet context was not " + "supplied as application context. A user of the " +