Application.java:
* Check logdir app property in updateProperties() rather than in getLogger(). * Only set helma.logdir system property if it isn't already set to prevent conflicts between applications. * Insert new repositories at the beginning of the list in addRepository(). * Some cleanup. ApplicationBean.java: * Use "helma.[appname].app" as default log name for messages logged through app.log(), app.debug(). * Introduce app.getLogger() and app.getLogger(name) that return a Jakarta commons Log instance. The zero argument method uses "helma.[appname].app" as category name. * Added and fixed some JavaDocs.
This commit is contained in:
parent
4bb6f72baa
commit
ed6712719c
2 changed files with 83 additions and 68 deletions
|
@ -108,6 +108,8 @@ public final class Application implements IPathElement, Runnable {
|
||||||
// Map of requesttrans -> active requestevaluators
|
// Map of requesttrans -> active requestevaluators
|
||||||
Hashtable activeRequests;
|
Hashtable activeRequests;
|
||||||
|
|
||||||
|
String logDir;
|
||||||
|
|
||||||
// Two logs for each application
|
// Two logs for each application
|
||||||
Log eventLog;
|
Log eventLog;
|
||||||
Log accessLog;
|
Log accessLog;
|
||||||
|
@ -251,8 +253,10 @@ public final class Application implements IPathElement, Runnable {
|
||||||
props = new ResourceProperties(this, "app.properties", sysProps);
|
props = new ResourceProperties(this, "app.properties", sysProps);
|
||||||
|
|
||||||
// get log names
|
// get log names
|
||||||
accessLogName = props.getProperty("accessLog", "helma."+name+".access");
|
accessLogName = props.getProperty("accessLog",
|
||||||
eventLogName = props.getProperty("eventLog", "helma."+name+".event");
|
new StringBuffer("helma.").append(name).append(".access").toString());
|
||||||
|
eventLogName = props.getProperty("eventLog",
|
||||||
|
new StringBuffer("helma.").append(name).append(".event").toString());
|
||||||
|
|
||||||
// create app-level db sources
|
// create app-level db sources
|
||||||
dbProps = new ResourceProperties(this, "db.properties", sysDbProps, false);
|
dbProps = new ResourceProperties(this, "db.properties", sysDbProps, false);
|
||||||
|
@ -303,17 +307,16 @@ public final class Application implements IPathElement, Runnable {
|
||||||
|
|
||||||
// create and init type mananger
|
// create and init type mananger
|
||||||
typemgr = new TypeManager(this, ignoreDirs);
|
typemgr = new TypeManager(this, ignoreDirs);
|
||||||
|
// set the context classloader. Note that this must be done before
|
||||||
|
// using the logging framework so that a new LogFactory gets created
|
||||||
|
// for this app.
|
||||||
|
Thread.currentThread().setContextClassLoader(typemgr.getClassLoader());
|
||||||
try {
|
try {
|
||||||
typemgr.createPrototypes();
|
typemgr.createPrototypes();
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
logError("Error creating prototypes", x);
|
logError("Error creating prototypes", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the context classloader. Note that this must be done before
|
|
||||||
// using the logging framework so that a new LogFactory gets created
|
|
||||||
// for this app.
|
|
||||||
Thread.currentThread().setContextClassLoader(typemgr.getClassLoader());
|
|
||||||
|
|
||||||
if (Server.getServer() != null) {
|
if (Server.getServer() != null) {
|
||||||
Vector extensions = Server.getServer().getExtensions();
|
Vector extensions = Server.getServer().getExtensions();
|
||||||
|
|
||||||
|
@ -1150,23 +1153,26 @@ public final class Application implements IPathElement, Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the prototype name that Hrefs in this application should start with.
|
* Returns the prototype name that Hrefs in this application should
|
||||||
|
* start with.
|
||||||
*/
|
*/
|
||||||
public String getHrefRootPrototype() {
|
public String getHrefRootPrototype() {
|
||||||
return hrefRootPrototype;
|
return hrefRootPrototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell other classes whether they should output logging information for this application.
|
* Tell other classes whether they should output logging information for
|
||||||
|
* this application.
|
||||||
*/
|
*/
|
||||||
public boolean debug() {
|
public boolean debug() {
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the current RequestEvaluator, or null if the calling thread
|
||||||
|
* is not evaluating a request.
|
||||||
*
|
*
|
||||||
*
|
* @return the RequestEvaluator belonging to the current thread
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public RequestEvaluator getCurrentRequestEvaluator() {
|
public RequestEvaluator getCurrentRequestEvaluator() {
|
||||||
Thread thread = Thread.currentThread();
|
Thread thread = Thread.currentThread();
|
||||||
|
@ -1406,16 +1412,9 @@ public final class Application implements IPathElement, Runnable {
|
||||||
* Get a logger object to log events for this application.
|
* Get a logger object to log events for this application.
|
||||||
*/
|
*/
|
||||||
public Log getLogger(String logname) {
|
public Log getLogger(String logname) {
|
||||||
String logdir = props.getProperty("logdir", "log");
|
if ("console".equals(logDir) || "console".equals(logname)) {
|
||||||
|
|
||||||
if ("console".equals(logdir) || "console".equals(logname)) {
|
|
||||||
return Logging.getConsoleLog();
|
return Logging.getConsoleLog();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// set up helma.logdir system property in case we're using it
|
|
||||||
File dir = new File(logdir);
|
|
||||||
System.setProperty("helma.logdir", dir.getAbsolutePath());
|
|
||||||
|
|
||||||
return LogFactory.getLog(logname);
|
return LogFactory.getLog(logname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1698,7 +1697,7 @@ public final class Application implements IPathElement, Runnable {
|
||||||
* Add a repository to this app's repository list. This is used for
|
* Add a repository to this app's repository list. This is used for
|
||||||
* ZipRepositories contained in top-level file repositories, for instance.
|
* ZipRepositories contained in top-level file repositories, for instance.
|
||||||
*
|
*
|
||||||
* @param rep
|
* @param rep the repository to add
|
||||||
* @return if the repository was not yet contained
|
* @return if the repository was not yet contained
|
||||||
*/
|
*/
|
||||||
public boolean addRepository(Repository rep) {
|
public boolean addRepository(Repository rep) {
|
||||||
|
@ -1715,7 +1714,7 @@ public final class Application implements IPathElement, Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no parent or parent not in app's repositories.
|
// no parent or parent not in app's repositories.
|
||||||
repositories.add(rep);
|
repositories.add(0, rep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1833,6 +1832,13 @@ public final class Application implements IPathElement, Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logDir = props.getProperty("logdir", "log");
|
||||||
|
if (System.getProperty("helma.logdir") == null) {
|
||||||
|
// set up helma.logdir system property in case we're using it
|
||||||
|
File dir = new File(logDir);
|
||||||
|
System.setProperty("helma.logdir", dir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
// set prop read timestamp
|
// set prop read timestamp
|
||||||
lastPropertyRead = props.lastModified();
|
lastPropertyRead = props.lastModified();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,12 +25,15 @@ import java.io.File;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ApplicationBean implements Serializable {
|
public class ApplicationBean implements Serializable {
|
||||||
Application app;
|
Application app;
|
||||||
|
Log appLog;
|
||||||
WrappedMap properties = null;
|
WrappedMap properties = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,59 +46,77 @@ public class ApplicationBean implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Clear the application cache.
|
||||||
*/
|
*/
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
app.clearCache();
|
app.clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the app logger. This is a commons-logging Log with the
|
||||||
|
* category helma.[appname].app.
|
||||||
*
|
*
|
||||||
|
* @return the app logger.
|
||||||
|
*/
|
||||||
|
public synchronized Log getLogger() {
|
||||||
|
if (appLog == null) {
|
||||||
|
appLog = app.getLogger(new StringBuffer("helma.")
|
||||||
|
.append(app.getName()).append(".app").toString());
|
||||||
|
}
|
||||||
|
return appLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the app logger. This is a commons-logging Log with the
|
||||||
|
* category <code>logname</code>.
|
||||||
*
|
*
|
||||||
* @param msg ...
|
* @return a logger for the given log name.
|
||||||
|
*/
|
||||||
|
public Log getLogger(String logname) {
|
||||||
|
return LogFactory.getLog(logname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a INFO message to the app log.
|
||||||
|
*
|
||||||
|
* @param msg the log message
|
||||||
*/
|
*/
|
||||||
public void log(Object msg) {
|
public void log(Object msg) {
|
||||||
String str = (msg == null) ? "null" : msg.toString();
|
getLogger().info(msg);
|
||||||
|
|
||||||
app.logEvent(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Log a INFO message to the app log.
|
||||||
*
|
*
|
||||||
*
|
* @param logname the name (category) of the log
|
||||||
* @param logname ...
|
* @param msg the log message
|
||||||
* @param msg ...
|
|
||||||
*/
|
*/
|
||||||
public void log(String logname, Object msg) {
|
public void log(String logname, Object msg) {
|
||||||
String str = (msg == null) ? "null" : msg.toString();
|
getLogger(logname).info(msg);
|
||||||
|
|
||||||
app.getLogger(logname).info(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Log a DEBUG message to the app log if debug is set to true in
|
||||||
|
* app.properties.
|
||||||
*
|
*
|
||||||
*
|
* @param msg the log message
|
||||||
* @param msg ...
|
|
||||||
*/
|
*/
|
||||||
public void debug(Object msg) {
|
public void debug(Object msg) {
|
||||||
if (app.debug()) {
|
if (app.debug()) {
|
||||||
String str = (msg == null) ? "null" : msg.toString();
|
getLogger().debug(msg);
|
||||||
|
|
||||||
app.logEvent(str);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Log a DEBUG message to the app log if debug is set to true in
|
||||||
|
* app.properties.
|
||||||
*
|
*
|
||||||
*
|
* @param logname the name (category) of the log
|
||||||
* @param logname ...
|
* @param msg the log message
|
||||||
* @param msg ...
|
|
||||||
*/
|
*/
|
||||||
public void debug(String logname, Object msg) {
|
public void debug(String logname, Object msg) {
|
||||||
if (app.debug()) {
|
if (app.debug()) {
|
||||||
String str = (msg == null) ? "null" : msg.toString();
|
getLogger(logname).debug(msg);
|
||||||
|
|
||||||
app.getLogger(logname).info(str);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +183,7 @@ public class ApplicationBean implements Serializable {
|
||||||
|
|
||||||
Iterator it = sessions.values().iterator();
|
Iterator it = sessions.values().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
array[i++] = new SessionBean((Session) it.next());
|
array[i++] = new SessionBean((Session) it.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
|
@ -296,7 +317,7 @@ public class ApplicationBean implements Serializable {
|
||||||
/**
|
/**
|
||||||
* Returns an read-only map of the custom cron jobs registered with the app
|
* Returns an read-only map of the custom cron jobs registered with the app
|
||||||
*
|
*
|
||||||
* @return
|
* @return a map of cron jobs
|
||||||
*/
|
*/
|
||||||
public Map getCronJobs() {
|
public Map getCronJobs() {
|
||||||
return new WrappedMap(app.customCronJobs, true);
|
return new WrappedMap(app.customCronJobs, true);
|
||||||
|
@ -312,7 +333,7 @@ public class ApplicationBean implements Serializable {
|
||||||
/**
|
/**
|
||||||
* Returns the app's data node used to share data between the app's evaluators
|
* Returns the app's data node used to share data between the app's evaluators
|
||||||
*
|
*
|
||||||
* @return
|
* @return the app.data node
|
||||||
*/
|
*/
|
||||||
public INode getData() {
|
public INode getData() {
|
||||||
return app.getCacheNode();
|
return app.getCacheNode();
|
||||||
|
@ -321,7 +342,7 @@ public class ApplicationBean implements Serializable {
|
||||||
/**
|
/**
|
||||||
* Returns the app's modules map used to register application modules
|
* Returns the app's modules map used to register application modules
|
||||||
*
|
*
|
||||||
* @return
|
* @return the module map
|
||||||
*/
|
*/
|
||||||
public Map getModules() {
|
public Map getModules() {
|
||||||
return app.modules;
|
return app.modules;
|
||||||
|
@ -331,61 +352,49 @@ public class ApplicationBean implements Serializable {
|
||||||
* Returns the absolute path of the app dir. When using repositories this
|
* Returns the absolute path of the app dir. When using repositories this
|
||||||
* equals the first file based repository.
|
* equals the first file based repository.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the app dir
|
||||||
*/
|
*/
|
||||||
public String getDir() {
|
public String getDir() {
|
||||||
return app.getAppDir().getAbsolutePath();
|
return app.getAppDir().getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the app name
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return app.getName();
|
return app.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the application start time
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public Date getUpSince() {
|
public Date getUpSince() {
|
||||||
return new Date(app.starttime);
|
return new Date(app.starttime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the number of requests processed by this app
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public long getRequestCount() {
|
public long getRequestCount() {
|
||||||
return app.getRequestCount();
|
return app.getRequestCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the number of XML-RPC requests processed
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public long getXmlrpcCount() {
|
public long getXmlrpcCount() {
|
||||||
return app.getXmlrpcCount();
|
return app.getXmlrpcCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the number of errors encountered
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public long getErrorCount() {
|
public long getErrorCount() {
|
||||||
return app.getErrorCount();
|
return app.getErrorCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the wrapped helma.framework.core.Application object
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public Application get__app__() {
|
public Application get__app__() {
|
||||||
return app;
|
return app;
|
||||||
|
@ -474,7 +483,7 @@ public class ApplicationBean implements Serializable {
|
||||||
// add one to the number to compensate for the internal scheduler.
|
// add one to the number to compensate for the internal scheduler.
|
||||||
app.setNumberOfEvaluators(n + 1);
|
app.setNumberOfEvaluators(n + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a skin for a given object. The skin is found by determining the prototype
|
* Return a skin for a given object. The skin is found by determining the prototype
|
||||||
* to use for the object, then looking up the skin for the prototype.
|
* to use for the object, then looking up the skin for the prototype.
|
||||||
|
|
Loading…
Add table
Reference in a new issue