mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-05 23:22:47 +00:00
Implements logging service configuration
This commit is contained in:
@@ -39,7 +39,6 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Scopes;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.util.ClassUtils;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
@@ -52,7 +51,7 @@ public class ServiceManager {
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private Logger logger;
|
||||
private final Logger logger = LoggerFactory.getLogger(ServiceManager.class);
|
||||
/**
|
||||
* The Guice Injector
|
||||
*/
|
||||
@@ -131,14 +130,15 @@ public class ServiceManager {
|
||||
*/
|
||||
public void init(Injector injector) throws ServiceStartException {
|
||||
this.injector = injector;
|
||||
final LoggingService service = injector
|
||||
.getInstance(LoggingService.class);
|
||||
knownServices.add(service);
|
||||
service.start();
|
||||
configurationService = injector.getInstance(ConfigurationService.class);
|
||||
knownServices.add(configurationService);
|
||||
configurationService.start();
|
||||
logger = LoggerFactory.getLogger(ServiceManager.class);
|
||||
// final LoggingService service = injector
|
||||
// .getInstance(LoggingService.class);
|
||||
// knownServices.add(service);
|
||||
// service.start();
|
||||
configurationService = start(ConfigurationService.class);
|
||||
//start(LoggingService.class);
|
||||
//knownServices.add(configurationService);
|
||||
//start(ConfigurationService.class);
|
||||
//configurationService.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,16 +35,13 @@ import org.w3c.dom.Node;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ConfigurableService;
|
||||
import com.l2jserver.service.Service;
|
||||
import com.l2jserver.service.ServiceConfiguration;
|
||||
import com.l2jserver.service.ServiceDescriptor;
|
||||
import com.l2jserver.service.ServiceManager;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.cache.CacheService;
|
||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
import com.l2jserver.util.transformer.Transformer;
|
||||
import com.l2jserver.util.transformer.TransformerFactory;
|
||||
@@ -55,7 +52,6 @@ import com.l2jserver.util.transformer.TransformerFactory;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends({ LoggingService.class, CacheService.class })
|
||||
public class XMLConfigurationService extends AbstractService implements
|
||||
ConfigurationService {
|
||||
/**
|
||||
@@ -174,12 +170,16 @@ public class XMLConfigurationService extends AbstractService implements
|
||||
return cache.get(xpath.value());
|
||||
Object o;
|
||||
try {
|
||||
o = untransform(getRaw(xpath.value(), getter.defaultValue()),
|
||||
type);
|
||||
if (type == Node.class) {
|
||||
o = getNode(xpath.value());
|
||||
} else {
|
||||
o = untransform(
|
||||
getRaw(xpath.value(), getter.defaultValue()), type);
|
||||
cache.put(xpath.value(), o);
|
||||
}
|
||||
} catch (XPathExpressionException e) {
|
||||
return null;
|
||||
}
|
||||
cache.put(xpath.value(), o);
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -201,8 +201,12 @@ public class XMLConfigurationService extends AbstractService implements
|
||||
.compile(xpath.value())
|
||||
.evaluate(properties, XPathConstants.NODE);
|
||||
if (value != null) {
|
||||
node.setNodeValue(transform(value.toString(), type));
|
||||
cache.put(xpath.value(), value);
|
||||
if (type == Node.class) {
|
||||
node.getParentNode().replaceChild(node, (Node) value);
|
||||
} else {
|
||||
node.setNodeValue(transform(value.toString(), type));
|
||||
cache.put(xpath.value(), value);
|
||||
}
|
||||
} else {
|
||||
node.getParentNode().removeChild(node);
|
||||
cache.remove(xpath.value());
|
||||
@@ -274,6 +278,20 @@ public class XMLConfigurationService extends AbstractService implements
|
||||
return defaultValue;
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the node object from the property file
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @return the node returned by the xpath query
|
||||
* @throws XPathExpressionException
|
||||
* if any XPath exception occur
|
||||
*/
|
||||
private Node getNode(String key) throws XPathExpressionException {
|
||||
return (Node) XPathFactory.newInstance().newXPath().compile(key)
|
||||
.evaluate(properties, XPathConstants.NODE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,8 +22,11 @@ import org.apache.log4j.Layout;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PatternLayout;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractConfigurableService;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
|
||||
@@ -32,39 +35,42 @@ import com.l2jserver.service.ServiceStopException;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class Log4JLoggingService extends AbstractService implements
|
||||
public class Log4JLoggingService extends
|
||||
AbstractConfigurableService<LoggingServiceConfiguration> implements
|
||||
LoggingService {
|
||||
/**
|
||||
* The root logger
|
||||
*/
|
||||
private Logger rootLogger;
|
||||
|
||||
/**
|
||||
* The l2j logger
|
||||
* Creates a new instance
|
||||
*/
|
||||
private Logger l2jLogger;
|
||||
/**
|
||||
* The netty logger
|
||||
*/
|
||||
private Logger nettyLogger;
|
||||
public Log4JLoggingService() {
|
||||
super(LoggingServiceConfiguration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ServiceStartException {
|
||||
final Layout layout = new PatternLayout(
|
||||
"[%p %d{yyyy-MM-dd HH-mm-ss}] %c:%L - %m%n");
|
||||
|
||||
BasicConfigurator.configure();
|
||||
"[%p %d] %c{1} - %m%n");
|
||||
rootLogger = Logger.getRootLogger();
|
||||
l2jLogger = Logger.getLogger("com.l2jserver");
|
||||
nettyLogger = Logger.getLogger("org.jboss.netty");
|
||||
|
||||
rootLogger.removeAllAppenders();
|
||||
rootLogger.setLevel(Level.WARN);
|
||||
// rootLogger.setLevel(config.getLoggersNode().);
|
||||
rootLogger.addAppender(new ConsoleAppender(layout, "System.err"));
|
||||
|
||||
l2jLogger.setLevel(Level.INFO);
|
||||
nettyLogger.setLevel(Level.DEBUG);
|
||||
Logger.getLogger("com.l2jserver.model.id.object.allocator").setLevel(
|
||||
Level.WARN);
|
||||
final NodeList nodes = config.getLoggersNode().getChildNodes();
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
final Node node = nodes.item(i);
|
||||
if (!"logger".equals(node.getNodeName()))
|
||||
continue;
|
||||
final NamedNodeMap attributes = node.getAttributes();
|
||||
final Logger logger = Logger.getLogger(attributes.getNamedItem(
|
||||
"name").getNodeValue());
|
||||
logger.setLevel(Level.toLevel(attributes.getNamedItem("level")
|
||||
.getNodeValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.service.core;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.l2jserver.service.ServiceConfiguration;
|
||||
import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface LoggingServiceConfiguration extends ServiceConfiguration {
|
||||
/**
|
||||
* @return the loggers node
|
||||
*/
|
||||
@ConfigurationPropertyGetter
|
||||
@ConfigurationXPath(".")
|
||||
Node getLoggersNode();
|
||||
|
||||
/**
|
||||
* @param loggersNode
|
||||
* the loggers node
|
||||
*/
|
||||
@ConfigurationPropertySetter
|
||||
@ConfigurationXPath(".")
|
||||
void setLoggersNode(Node loggersNode);
|
||||
}
|
||||
@@ -47,14 +47,19 @@
|
||||
you normally don't need to change anything here nor in the firewall. -->
|
||||
<server listen="0.0.0.0:7777" />
|
||||
</service>
|
||||
|
||||
<!-- Logging service -->
|
||||
<service interface="com.l2jserver.service.core.LoggingService"
|
||||
implementation="com.l2jserver.service.core.Log4JLoggingService">
|
||||
<logger name="" level="ERROR" />
|
||||
<logger name="com.l2jserver" level="INFO" />
|
||||
</service>
|
||||
|
||||
<!-- ###################################################################### -->
|
||||
<!-- ########################### CORE SERVICES ############################ -->
|
||||
<!-- ###################################################################### -->
|
||||
<!-- Those services provide basic core features and are required for server
|
||||
startup process -->
|
||||
<service interface="com.l2jserver.service.core.LoggingService"
|
||||
implementation="com.l2jserver.service.core.Log4JLoggingService" />
|
||||
<service interface="com.l2jserver.service.core.threading.ThreadService"
|
||||
implementation="com.l2jserver.service.core.threading.ThreadServiceImpl" />
|
||||
<service interface="com.l2jserver.service.configuration.ConfigurationService"
|
||||
|
||||
@@ -58,14 +58,24 @@
|
||||
you normally don't need to change anything here nor in the firewall. -->
|
||||
<server listen="0.0.0.0:7777" />
|
||||
</service>
|
||||
|
||||
<!-- Logging service -->
|
||||
<service interface="com.l2jserver.service.core.LoggingService"
|
||||
implementation="com.l2jserver.service.core.Log4JLoggingService">
|
||||
<logger name="" level="ERROR" />
|
||||
<logger name="com.l2jserver" level="INFO" />
|
||||
<logger name="com.l2jserver.service.game.template.XMLTemplateService" level="INFO" />
|
||||
<logger name="com.l2jserver.service.cache" level="INFO" />
|
||||
<logger name="com.l2jserver.service.database.sql.AbstractSQLDatabaseService" level="INFO" />
|
||||
<logger name="com.l2jserver.service.game.world.CachedWorldIDService" level="INFO" />
|
||||
<logger name="com.l2jserver.model.id.object.allocator.BitSetIDAllocator" level="INFO" />
|
||||
</service>
|
||||
|
||||
<!-- ###################################################################### -->
|
||||
<!-- ########################### CORE SERVICES ############################ -->
|
||||
<!-- ###################################################################### -->
|
||||
<!-- Those services provide basic core features and are required for server
|
||||
startup process -->
|
||||
<service interface="com.l2jserver.service.core.LoggingService"
|
||||
implementation="com.l2jserver.service.core.Log4JLoggingService" />
|
||||
<service interface="com.l2jserver.service.core.threading.ThreadService"
|
||||
implementation="com.l2jserver.service.core.threading.ThreadServiceImpl" />
|
||||
<service interface="com.l2jserver.service.configuration.ConfigurationService"
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.nio.file.Paths;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@@ -77,6 +78,8 @@ public class L2JGameServerMain {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void main(String[] args) {
|
||||
BasicConfigurator.configure();
|
||||
|
||||
final ServiceManager serviceManager = new ServiceManager();
|
||||
try {
|
||||
serviceManager.load(Paths.get("services.xml"));
|
||||
|
||||
Reference in New Issue
Block a user