From 0099205ac92eb175dfd011c3626462f206d7d06a Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 20 Nov 2001 21:08:35 +0000 Subject: [PATCH] Added a log system implementation that routes log messages to the servlet context so that we don't have to fiddle around with Velocity trying to create velocity.log files in inopportune places that collide with velocity.log files from other Velocity-using applications. git-svn-id: https://samskivert.googlecode.com/svn/trunk@459 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../velocity/ServletContextLogger.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 projects/samskivert/src/java/com/samskivert/velocity/ServletContextLogger.java diff --git a/projects/samskivert/src/java/com/samskivert/velocity/ServletContextLogger.java b/projects/samskivert/src/java/com/samskivert/velocity/ServletContextLogger.java new file mode 100644 index 00000000..423639fd --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/velocity/ServletContextLogger.java @@ -0,0 +1,56 @@ +// +// $Id: ServletContextLogger.java,v 1.1 2001/11/20 21:08:35 mdb Exp $ +// +// samskivert library - useful routines for java programs +// Copyright (C) 2001 Michael Bayne +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.velocity; + +import javax.servlet.ServletContext; + +import org.apache.velocity.runtime.RuntimeServices; +import org.apache.velocity.runtime.log.LogSystem; + +/** + * Routes Velocity log messages to the servlet context. + */ +public class ServletContextLogger implements LogSystem +{ + // 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 (_sctx == null) { + rsvc.warn("ServletContextLogger: servlet context was not " + + "supplied as application context. A user of the " + + "servlet context logger must call " + + "Velocity.setApplicationContext(getServletContext())."); + } + } + + // documentation inherited + public void logVelocityMessage (int level, String message) + { + // log everything for now + _sctx.log(message); + } + + /** A reference to our servlet context. */ + protected ServletContext _sctx; +}