[DS-340] DSpace services log to the command line

git-svn-id: http://scm.dspace.org/svn/repo/modules/dspace-services/trunk@4545 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Mark Diggory
2009-11-19 00:38:34 +00:00
parent 2dcf6e019a
commit 5a6b223dd8
8 changed files with 52 additions and 25 deletions

View File

@@ -36,6 +36,8 @@ import org.dspace.kernel.ServiceManager;
import org.dspace.servicemanager.config.DSpaceConfigurationService;
import org.dspace.services.ConfigurationService;
import org.dspace.utils.DSpace;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is the kernel implementation which starts up the core of DSpace and
@@ -51,6 +53,7 @@ import org.dspace.utils.DSpace;
*/
public class DSpaceKernelImpl implements DSpaceKernel, DynamicMBean, CommonLifecycle<DSpaceKernel> {
private static Logger log = LoggerFactory.getLogger(DSpaceKernelImpl.class);
/**
* Creates a DSpace Kernel, does not do any checks though,
* do not call this, use {@link DSpaceKernelInit#getKernel(String)}
@@ -151,7 +154,7 @@ public class DSpaceKernelImpl implements DSpaceKernel, DynamicMBean, CommonLifec
running = true;
// add in the shutdown hook
registerShutdownHook();
System.out.println("INFO DSpace kernel startup completed in "+loadTime+" ms and registered as MBean: " + mBeanName);
log.info("DSpace kernel startup completed in "+loadTime+" ms and registered as MBean: " + mBeanName);
}
}
@@ -175,7 +178,7 @@ public class DSpaceKernelImpl implements DSpaceKernel, DynamicMBean, CommonLifec
serviceManagerSystem = null;
configurationService = null;
// log completion (logger may be gone at this point so we cannot really use it)
System.out.println("INFO: DSpace kernel shutdown completed and unregistered MBean: " + mBeanName);
log.info("DSpace kernel shutdown completed and unregistered MBean: " + mBeanName);
}
}
@@ -202,7 +205,7 @@ public class DSpaceKernelImpl implements DSpaceKernel, DynamicMBean, CommonLifec
}
} catch (Exception e) {
// cannot use the logger here as it is already gone at this point
System.out.println("INFO: Failed to unregister the MBean: " + mBeanName);
log.error("INFO: Failed to unregister the MBean: " + mBeanName, e);
}
// trash the shutdown hook as we do not need it anymore
if (this.shutdownHook != null) {
@@ -232,7 +235,7 @@ public class DSpaceKernelImpl implements DSpaceKernel, DynamicMBean, CommonLifec
try {
doDestroy();
} catch (Exception e) {
System.out.println("WARN Failure attempting to cleanup the DSpace kernel: " + e.getMessage());
log.error("WARN Failure attempting to cleanup the DSpace kernel: " + e.getMessage(), e);
}
}

View File

@@ -24,6 +24,8 @@ import javax.management.ReflectionException;
import org.dspace.kernel.DSpaceKernel;
import org.dspace.kernel.DSpaceKernelManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class simplifies the handling of MBean lookup, registration, etc. of the DSpace Kernel MBean.
@@ -33,6 +35,8 @@ import org.dspace.kernel.DSpaceKernelManager;
*/
public class DSpaceKernelInit {
private static Logger log = LoggerFactory.getLogger(DSpaceKernelInit.class);
private static Object staticLock = new Object();
/**
@@ -51,7 +55,7 @@ public class DSpaceKernelInit {
}
if (kernel == null) {
DSpaceKernelImpl kernelImpl = new DSpaceKernelImpl(mBeanName);
System.out.println("INFO Created new kernel: " + kernelImpl);
log.info("Created new kernel: " + kernelImpl);
// register the bean
String beanName = kernelImpl.getMBeanName();
register(beanName, kernelImpl);
@@ -76,7 +80,7 @@ public class DSpaceKernelInit {
if (! mbs.isRegistered(name)) {
// register the MBean
mbs.registerMBean(kernel, name);
System.out.println("INFO Registered new Kernel MBEAN: " + mBeanName + " ["+kernel+"]");
log.info("Registered new Kernel MBEAN: " + mBeanName + " ["+kernel+"]");
}
} catch (MalformedObjectNameException e) {
throw new IllegalStateException(e);
@@ -106,7 +110,7 @@ public class DSpaceKernelInit {
mbs.unregisterMBean(name);
return true;
} catch (Exception e) {
System.out.println("WARN Failed to unregister the MBean: " + mBeanName);
log.error("WARN Failed to unregister the MBean: " + mBeanName);
return false;
}
}

View File

@@ -33,6 +33,8 @@ import org.dspace.servicemanager.ServiceMixinManager.ServiceHolder;
import org.dspace.servicemanager.config.DSpaceConfig;
import org.dspace.servicemanager.config.DSpaceConfigurationService;
import org.dspace.servicemanager.spring.SpringServiceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is the core service manager which ties together the other
@@ -42,6 +44,8 @@ import org.dspace.servicemanager.spring.SpringServiceManager;
*/
public class DSpaceServiceManager implements ServiceManagerSystem {
private static Logger log = LoggerFactory.getLogger(DSpaceServiceManager.class);
private final DSpaceConfigurationService configurationService;
protected boolean running = false;
@@ -139,9 +143,9 @@ public class DSpaceServiceManager implements ServiceManagerSystem {
try {
activator.start(this);
activators.add(activator);
System.out.println("Started and registered activator: " + activatorClassName);
log.info("Started and registered activator: " + activatorClassName);
} catch (Exception e1) {
System.err.println("ERROR: Failed to start activator ("+activatorClassName+"): " + e1);
log.error("ERROR: Failed to start activator ("+activatorClassName+"): " + e1, e1);
}
}
}
@@ -157,9 +161,9 @@ public class DSpaceServiceManager implements ServiceManagerSystem {
// succeeded creating the activator
try {
activator.stop(this);
System.out.println("Stopped and unregistered activator: " + activatorClassName);
log.info("Stopped and unregistered activator: " + activatorClassName);
} catch (Exception e1) {
System.err.println("ERROR: Failed to stop activator ("+activatorClassName+"): " + e1);
log.error("ERROR: Failed to stop activator ("+activatorClassName+"): " + e1,e1);
}
}
}
@@ -267,7 +271,7 @@ public class DSpaceServiceManager implements ServiceManagerSystem {
this.serviceManagers.clear();
this.serviceMixinManager.clear();
this.primaryServiceManager = null;
System.out.println("Shutdown DSpace core service manager");
log.info("Shutdown DSpace core service manager");
}
public void startup() {
@@ -304,7 +308,7 @@ public class DSpaceServiceManager implements ServiceManagerSystem {
this.serviceMixinManager.registerService(entry.getKey(), entry.getValue());
}
}
System.out.println("Registered "+this.serviceMixinManager.size()+" service's mixins from loaded core services");
log.info("Registered "+this.serviceMixinManager.size()+" service's mixins from loaded core services");
// this kind of thing will be handled by DI utils -AZ
// // now start the secondary SMS using the spring bean factory
@@ -319,7 +323,7 @@ public class DSpaceServiceManager implements ServiceManagerSystem {
//
// // add it to the list of service managers
// serviceManagers.add(eSMS);
// System.out.println("Started up DSpace external service manager: " + serviceManagerClassName);
// log.info("Started up DSpace external service manager: " + serviceManagerClassName);
// } catch (Exception e) {
// // startup failures are deadly
// throw new IllegalStateException("failure starting up service manager " + serviceManagerClassName + ": " + e.getMessage(), e);
@@ -569,9 +573,9 @@ public class DSpaceServiceManager implements ServiceManagerSystem {
for (ServiceConfig config : configs.values()) {
try {
reflectUtils.setFieldValue(service, config.getParamName(), config.getValue());
System.out.println("Set param ("+config.getParamName()+") on service bean ("+serviceName+") to: " + config.getValue());
log.info("Set param ("+config.getParamName()+") on service bean ("+serviceName+") to: " + config.getValue());
} catch (RuntimeException e) {
System.err.println("Unable to set param ("+config.getParamName()+") on service bean ("+serviceName+"): " + e.getMessage());
log.error("Unable to set param ("+config.getParamName()+") on service bean ("+serviceName+"): " + e.getMessage(), e);
}
}
}

View File

@@ -25,6 +25,8 @@ import java.util.Map.Entry;
import org.azeckoski.reflectutils.ReflectUtils;
import org.azeckoski.reflectutils.refmap.ReferenceMap;
import org.azeckoski.reflectutils.refmap.ReferenceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Borrowed from EntityBus since this already will handle the mixins for something correctly and easily,
@@ -34,6 +36,8 @@ import org.azeckoski.reflectutils.refmap.ReferenceType;
*/
public class ServiceMixinManager {
private static Logger log = LoggerFactory.getLogger(ServiceMixinManager.class);
/**
* This is a map from the serviceName only to the service and also
* from the bikey made from the serviceName AND the implemented interfaces and superclasses to the service,
@@ -229,7 +233,7 @@ public class ServiceMixinManager {
// ((RequestAware)service).setRequestGetter(requestGetter);
// }
}
System.out.println("INFO Registered service ("+service.getClass().getName()
log.info("Registered service ("+service.getClass().getName()
+") serviceName ("+serviceName+") with "+count+" mixins");
return classList;
}
@@ -283,7 +287,7 @@ public class ServiceMixinManager {
serviceNameMap.remove(key);
// do any cleanup that needs to be done when unregistering
// Nothing here right now
System.out.println("INFO Unregistered service mixin ("+mixin.getName()+") for serviceName ("+serviceName+")");
log.info("Unregistered service mixin ("+mixin.getName()+") for serviceName ("+serviceName+")");
}
/**

View File

@@ -354,11 +354,11 @@ public class DSpaceConfigurationService implements ConfigurationService {
if (key.startsWith(DSPACE_PREFIX)) {
String propName = key.substring(DSPACE_PREFIX.length());
String propVal = systemProps.getProperty(key);
System.out.println("INFO Loading system property as config: "+propName+"=>"+propVal);
log.info("Loading system property as config: "+propName+"=>"+propVal);
configMap.put(propName, propVal);
}
} catch (RuntimeException e) {
System.err.println("Failed to properly get config value from system property: " + o);
log.error("Failed to properly get config value from system property: " + o, e);
}
}
}

View File

@@ -24,6 +24,8 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This will allow us to put the configuration into beans as they are being created,
@@ -33,6 +35,8 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
*/
public class DSpaceBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
private static Logger log = LoggerFactory.getLogger(DSpaceBeanFactoryPostProcessor.class);
private DSpaceConfigurationService configurationService;
private ServiceManagerSystem parent;
private boolean testMode = false;
@@ -67,7 +71,7 @@ public class DSpaceBeanFactoryPostProcessor implements BeanFactoryPostProcessor
}
if (testMode) {
System.out.println("TEST Spring Service Manager running in test mode, no activators will be started");
log.info("Spring Service Manager running in test mode, no activators will be started");
} else {
// now register all autowire configured beans
for (DSpaceConfig config : configs) {
@@ -86,7 +90,7 @@ public class DSpaceBeanFactoryPostProcessor implements BeanFactoryPostProcessor
beanDef.setScope(AbstractBeanDefinition.SCOPE_SINGLETON);
registry.registerBeanDefinition(config.getActivatorName(), beanDef);
} catch (Exception e) {
System.err.println("Failed to register activator class from config: " + config + " :" + e);
log.error("Failed to register activator class from config: " + config + " :" + e, e);
}
}
}

View File

@@ -21,6 +21,8 @@ import org.dspace.servicemanager.config.DSpaceConfigurationService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Takes a list of paths to resources and turns them into different things (file/IS/resource),
@@ -31,6 +33,8 @@ import org.springframework.core.io.Resource;
*/
public class ResourceFinder {
private static Logger log = LoggerFactory.getLogger(ResourceFinder.class);
public static final String relativePath = DSpaceConfigurationService.DSPACE + "/";
public static final String environmentPathVariable = DSpaceConfigurationService.DSPACE_HOME;
@@ -43,7 +47,7 @@ public class ResourceFinder {
rs.add(r);
} catch (IllegalArgumentException e) {
// do not add if not found, just skip
System.out.println("WARN: " + e.getMessage() + ", continuing...");
log.error(e.getMessage() + ", continuing...");
}
}
}

View File

@@ -23,6 +23,8 @@ import org.dspace.kernel.DSpaceKernelManager;
import org.dspace.kernel.ServiceManager;
import org.dspace.services.RequestService;
import org.dspace.services.SessionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test servlet for trying out the jetty server
@@ -33,6 +35,8 @@ public class SampleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static Logger log = LoggerFactory.getLogger(SampleServlet.class);
private transient SessionService sessionService;
private transient RequestService requestService;
@@ -56,7 +60,7 @@ public class SampleServlet extends HttpServlet {
if (requestService == null) {
throw new IllegalStateException("Could not get the DSpace RequestService");
}
System.out.println("Servlet initialized");
log.info("Servlet initialized");
} catch (Exception e) {
throw new IllegalStateException("FAILURE during init of direct servlet: " + e.getMessage(), e);
}
@@ -80,7 +84,7 @@ public class SampleServlet extends HttpServlet {
writer.print(XHTML_FOOTER);
res.setStatus(HttpServletResponse.SC_OK);
System.out.println("Serviced request: DSpace");
log.info("Serviced request: DSpace");
}
protected static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";