1 16 17 package org.apache.velocity.tools.view.servlet; 18 19 20 import javax.servlet.ServletContext ; 21 22 import org.apache.velocity.runtime.log.LogSystem; 23 import org.apache.velocity.runtime.RuntimeConstants; 24 import org.apache.velocity.runtime.RuntimeServices; 25 26 27 34 public class ServletLogger implements LogSystem 35 { 36 protected ServletContext servletContext = null; 37 38 public static final String PREFIX = " Velocity "; 39 40 47 public ServletLogger() 48 { 49 } 50 51 57 public void init( RuntimeServices rs ) 58 throws Exception 59 { 60 Object obj = rs.getApplicationAttribute(ServletContext .class.getName()); 61 if (obj == null) 62 { 63 throw new IllegalStateException ("Could not retrieve ServletContext from application attributes!"); 64 } 65 servletContext = (ServletContext )obj; 66 } 67 68 71 public void logVelocityMessage(int level, String message) 72 { 73 switch (level) 74 { 75 case LogSystem.WARN_ID: 76 servletContext.log( PREFIX + RuntimeConstants.WARN_PREFIX + message ); 77 break; 78 case LogSystem.INFO_ID: 79 servletContext.log( PREFIX + RuntimeConstants.INFO_PREFIX + message); 80 break; 81 case LogSystem.DEBUG_ID: 82 servletContext.log( PREFIX + RuntimeConstants.DEBUG_PREFIX + message); 83 break; 84 case LogSystem.ERROR_ID: 85 servletContext.log( PREFIX + RuntimeConstants.ERROR_PREFIX + message); 86 break; 87 default: 88 servletContext.log( PREFIX + " : " + message); 89 break; 90 } 91 } 92 93 } 94 | Popular Tags |