Browse Source

moved log4j.properties file from classes directory to sibling of properties file, which is specified by a servlet context parameter.

tags/Production_2016_05_28
ymlam 11 years ago
parent
commit
785ea730b3
1 changed files with 25 additions and 2 deletions
  1. +25
    -2
      src/altk/comm/engine/CommEngine.java

+ 25
- 2
src/altk/comm/engine/CommEngine.java View File

@@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import altk.comm.engine.Broadcast.BroadcastState;
import altk.comm.engine.exception.BroadcastError;
@@ -66,7 +67,7 @@ public abstract class CommEngine extends HttpServlet
*/
protected EngineResources resources;
private static Logger myLogger = Logger.getLogger(CommEngine.class);
private static Logger myLogger;
private ScheduledExecutorService scheduler;

@@ -97,13 +98,35 @@ public abstract class CommEngine extends HttpServlet
*/
public final void init()
{
myLogger.info("init() invoked");
// check init parameters
ServletContext servletContext = getServletContext();
String propertiesFilePath;
propertiesFilePath = servletContext.getInitParameter(getPropertiesContextName());
File propertiesFile = new File(propertiesFilePath);
// Configure log4j using log4j.properties file, \
// sibling to the engine properties file.
// This change is backward compatible with placing the log4j.properties file in
// the class path.
String log4j_properties = propertiesFile.getParent() + "/log4j.properties";
try
{
PropertyConfigurator.configure(log4j_properties);
}
catch (Exception e)
{
// Do nothing, assuming the exception is FileNotFoundException.
// Remaining log4j initialization will look for log4j.properties
// file in the class path.
}
// This activates Logger class instantiation. At this point, if lo4j
// is not yet configured,
// it will look for the log4j.properties file in the class path.
myLogger = Logger.getLogger(CommEngine.class);
myLogger.info("init() invoked");
CommonLogger.startup.info("Using lo4j properites file " + log4j_properties);
CommonLogger.startup.info("Using configuration file " + propertiesFile.getAbsolutePath());
config = new Properties();
try


Loading…
Cancel
Save