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.Module;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
import com.l2jserver.service.configuration.ConfigurationService;
|
import com.l2jserver.service.configuration.ConfigurationService;
|
||||||
import com.l2jserver.service.core.LoggingService;
|
|
||||||
import com.l2jserver.util.ClassUtils;
|
import com.l2jserver.util.ClassUtils;
|
||||||
import com.l2jserver.util.factory.CollectionFactory;
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ public class ServiceManager {
|
|||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
*/
|
*/
|
||||||
private Logger logger;
|
private final Logger logger = LoggerFactory.getLogger(ServiceManager.class);
|
||||||
/**
|
/**
|
||||||
* The Guice Injector
|
* The Guice Injector
|
||||||
*/
|
*/
|
||||||
@@ -131,14 +130,15 @@ public class ServiceManager {
|
|||||||
*/
|
*/
|
||||||
public void init(Injector injector) throws ServiceStartException {
|
public void init(Injector injector) throws ServiceStartException {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
final LoggingService service = injector
|
// final LoggingService service = injector
|
||||||
.getInstance(LoggingService.class);
|
// .getInstance(LoggingService.class);
|
||||||
knownServices.add(service);
|
// knownServices.add(service);
|
||||||
service.start();
|
// service.start();
|
||||||
configurationService = injector.getInstance(ConfigurationService.class);
|
configurationService = start(ConfigurationService.class);
|
||||||
knownServices.add(configurationService);
|
//start(LoggingService.class);
|
||||||
configurationService.start();
|
//knownServices.add(configurationService);
|
||||||
logger = LoggerFactory.getLogger(ServiceManager.class);
|
//start(ConfigurationService.class);
|
||||||
|
//configurationService.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -35,16 +35,13 @@ import org.w3c.dom.Node;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
import com.l2jserver.service.AbstractService.Depends;
|
|
||||||
import com.l2jserver.service.ConfigurableService;
|
import com.l2jserver.service.ConfigurableService;
|
||||||
import com.l2jserver.service.Service;
|
import com.l2jserver.service.Service;
|
||||||
import com.l2jserver.service.ServiceConfiguration;
|
import com.l2jserver.service.ServiceConfiguration;
|
||||||
import com.l2jserver.service.ServiceDescriptor;
|
import com.l2jserver.service.ServiceDescriptor;
|
||||||
import com.l2jserver.service.ServiceManager;
|
import com.l2jserver.service.ServiceManager;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.cache.CacheService;
|
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
||||||
import com.l2jserver.service.core.LoggingService;
|
|
||||||
import com.l2jserver.util.factory.CollectionFactory;
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
import com.l2jserver.util.transformer.Transformer;
|
import com.l2jserver.util.transformer.Transformer;
|
||||||
import com.l2jserver.util.transformer.TransformerFactory;
|
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>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
@Depends({ LoggingService.class, CacheService.class })
|
|
||||||
public class XMLConfigurationService extends AbstractService implements
|
public class XMLConfigurationService extends AbstractService implements
|
||||||
ConfigurationService {
|
ConfigurationService {
|
||||||
/**
|
/**
|
||||||
@@ -174,12 +170,16 @@ public class XMLConfigurationService extends AbstractService implements
|
|||||||
return cache.get(xpath.value());
|
return cache.get(xpath.value());
|
||||||
Object o;
|
Object o;
|
||||||
try {
|
try {
|
||||||
o = untransform(getRaw(xpath.value(), getter.defaultValue()),
|
if (type == Node.class) {
|
||||||
type);
|
o = getNode(xpath.value());
|
||||||
|
} else {
|
||||||
|
o = untransform(
|
||||||
|
getRaw(xpath.value(), getter.defaultValue()), type);
|
||||||
|
cache.put(xpath.value(), o);
|
||||||
|
}
|
||||||
} catch (XPathExpressionException e) {
|
} catch (XPathExpressionException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
cache.put(xpath.value(), o);
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,8 +201,12 @@ public class XMLConfigurationService extends AbstractService implements
|
|||||||
.compile(xpath.value())
|
.compile(xpath.value())
|
||||||
.evaluate(properties, XPathConstants.NODE);
|
.evaluate(properties, XPathConstants.NODE);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
node.setNodeValue(transform(value.toString(), type));
|
if (type == Node.class) {
|
||||||
cache.put(xpath.value(), value);
|
node.getParentNode().replaceChild(node, (Node) value);
|
||||||
|
} else {
|
||||||
|
node.setNodeValue(transform(value.toString(), type));
|
||||||
|
cache.put(xpath.value(), value);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
node.getParentNode().removeChild(node);
|
node.getParentNode().removeChild(node);
|
||||||
cache.remove(xpath.value());
|
cache.remove(xpath.value());
|
||||||
@@ -274,6 +278,20 @@ public class XMLConfigurationService extends AbstractService implements
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
return value;
|
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.Level;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.log4j.PatternLayout;
|
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.ServiceStartException;
|
||||||
import com.l2jserver.service.ServiceStopException;
|
import com.l2jserver.service.ServiceStopException;
|
||||||
|
|
||||||
@@ -32,39 +35,42 @@ import com.l2jserver.service.ServiceStopException;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public class Log4JLoggingService extends AbstractService implements
|
public class Log4JLoggingService extends
|
||||||
|
AbstractConfigurableService<LoggingServiceConfiguration> implements
|
||||||
LoggingService {
|
LoggingService {
|
||||||
/**
|
/**
|
||||||
* The root logger
|
* The root logger
|
||||||
*/
|
*/
|
||||||
private Logger rootLogger;
|
private Logger rootLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The l2j logger
|
* Creates a new instance
|
||||||
*/
|
*/
|
||||||
private Logger l2jLogger;
|
public Log4JLoggingService() {
|
||||||
/**
|
super(LoggingServiceConfiguration.class);
|
||||||
* The netty logger
|
}
|
||||||
*/
|
|
||||||
private Logger nettyLogger;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
final Layout layout = new PatternLayout(
|
final Layout layout = new PatternLayout(
|
||||||
"[%p %d{yyyy-MM-dd HH-mm-ss}] %c:%L - %m%n");
|
"[%p %d] %c{1} - %m%n");
|
||||||
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
rootLogger = Logger.getRootLogger();
|
rootLogger = Logger.getRootLogger();
|
||||||
l2jLogger = Logger.getLogger("com.l2jserver");
|
|
||||||
nettyLogger = Logger.getLogger("org.jboss.netty");
|
|
||||||
|
|
||||||
rootLogger.removeAllAppenders();
|
rootLogger.removeAllAppenders();
|
||||||
rootLogger.setLevel(Level.WARN);
|
// rootLogger.setLevel(config.getLoggersNode().);
|
||||||
rootLogger.addAppender(new ConsoleAppender(layout, "System.err"));
|
rootLogger.addAppender(new ConsoleAppender(layout, "System.err"));
|
||||||
|
|
||||||
l2jLogger.setLevel(Level.INFO);
|
final NodeList nodes = config.getLoggersNode().getChildNodes();
|
||||||
nettyLogger.setLevel(Level.DEBUG);
|
for (int i = 0; i < nodes.getLength(); i++) {
|
||||||
Logger.getLogger("com.l2jserver.model.id.object.allocator").setLevel(
|
final Node node = nodes.item(i);
|
||||||
Level.WARN);
|
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
|
@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. -->
|
you normally don't need to change anything here nor in the firewall. -->
|
||||||
<server listen="0.0.0.0:7777" />
|
<server listen="0.0.0.0:7777" />
|
||||||
</service>
|
</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 ############################ -->
|
<!-- ########################### CORE SERVICES ############################ -->
|
||||||
<!-- ###################################################################### -->
|
<!-- ###################################################################### -->
|
||||||
<!-- Those services provide basic core features and are required for server
|
<!-- Those services provide basic core features and are required for server
|
||||||
startup process -->
|
startup process -->
|
||||||
<service interface="com.l2jserver.service.core.LoggingService"
|
|
||||||
implementation="com.l2jserver.service.core.Log4JLoggingService" />
|
|
||||||
<service interface="com.l2jserver.service.core.threading.ThreadService"
|
<service interface="com.l2jserver.service.core.threading.ThreadService"
|
||||||
implementation="com.l2jserver.service.core.threading.ThreadServiceImpl" />
|
implementation="com.l2jserver.service.core.threading.ThreadServiceImpl" />
|
||||||
<service interface="com.l2jserver.service.configuration.ConfigurationService"
|
<service interface="com.l2jserver.service.configuration.ConfigurationService"
|
||||||
|
|||||||
@@ -58,14 +58,24 @@
|
|||||||
you normally don't need to change anything here nor in the firewall. -->
|
you normally don't need to change anything here nor in the firewall. -->
|
||||||
<server listen="0.0.0.0:7777" />
|
<server listen="0.0.0.0:7777" />
|
||||||
</service>
|
</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 ############################ -->
|
<!-- ########################### CORE SERVICES ############################ -->
|
||||||
<!-- ###################################################################### -->
|
<!-- ###################################################################### -->
|
||||||
<!-- Those services provide basic core features and are required for server
|
<!-- Those services provide basic core features and are required for server
|
||||||
startup process -->
|
startup process -->
|
||||||
<service interface="com.l2jserver.service.core.LoggingService"
|
|
||||||
implementation="com.l2jserver.service.core.Log4JLoggingService" />
|
|
||||||
<service interface="com.l2jserver.service.core.threading.ThreadService"
|
<service interface="com.l2jserver.service.core.threading.ThreadService"
|
||||||
implementation="com.l2jserver.service.core.threading.ThreadServiceImpl" />
|
implementation="com.l2jserver.service.core.threading.ThreadServiceImpl" />
|
||||||
<service interface="com.l2jserver.service.configuration.ConfigurationService"
|
<service interface="com.l2jserver.service.configuration.ConfigurationService"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.nio.file.Paths;
|
|||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.w3c.dom.DOMException;
|
import org.w3c.dom.DOMException;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
@@ -77,6 +78,8 @@ public class L2JGameServerMain {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
BasicConfigurator.configure();
|
||||||
|
|
||||||
final ServiceManager serviceManager = new ServiceManager();
|
final ServiceManager serviceManager = new ServiceManager();
|
||||||
try {
|
try {
|
||||||
serviceManager.load(Paths.get("services.xml"));
|
serviceManager.load(Paths.get("services.xml"));
|
||||||
|
|||||||
Reference in New Issue
Block a user