001 package com.croftsoft.core.util.log;
002
003 import javax.servlet.Servlet;
004 import javax.servlet.ServletContext;
005
006 import com.croftsoft.core.lang.NullArgumentException;
007
008 /*********************************************************************
009 * Delegates logging to a ServletContext.
010 *
011 * @author
012 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
013 * @version
014 * 2001-02-27
015 *********************************************************************/
016
017 public final class ServletContextLog implements Log
018 //////////////////////////////////////////////////////////////////////
019 //////////////////////////////////////////////////////////////////////
020 {
021
022 private final ServletContext servletContext;
023
024 //////////////////////////////////////////////////////////////////////
025 //////////////////////////////////////////////////////////////////////
026
027 public ServletContextLog ( ServletContext servletContext )
028 //////////////////////////////////////////////////////////////////////
029 {
030 NullArgumentException.check (
031 this.servletContext = servletContext );
032 }
033
034 public ServletContextLog ( Servlet servlet )
035 //////////////////////////////////////////////////////////////////////
036 {
037 this ( servlet.getServletConfig ( ).getServletContext ( ) );
038 }
039
040 //////////////////////////////////////////////////////////////////////
041 //////////////////////////////////////////////////////////////////////
042
043 public void record ( String message )
044 //////////////////////////////////////////////////////////////////////
045 {
046 servletContext.log ( message );
047 }
048
049 public void record ( Throwable throwable )
050 //////////////////////////////////////////////////////////////////////
051 {
052 servletContext.log ( throwable.getMessage ( ), throwable );
053 }
054
055
056 public void record ( String message, Throwable throwable )
057 //////////////////////////////////////////////////////////////////////
058 {
059 servletContext.log ( message, throwable );
060 }
061
062 //////////////////////////////////////////////////////////////////////
063 //////////////////////////////////////////////////////////////////////
064 }