mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 01:19:02 +00:00
add jclouds logger
This commit is contained in:
parent
02bfa9c4cb
commit
fc30467b72
1
.idea/dictionaries/kimchy.xml
generated
1
.idea/dictionaries/kimchy.xml
generated
@ -36,6 +36,7 @@
|
||||
<w>intf</w>
|
||||
<w>iter</w>
|
||||
<w>iterable</w>
|
||||
<w>jclouds</w>
|
||||
<w>jgroups</w>
|
||||
<w>joda</w>
|
||||
<w>jsonp</w>
|
||||
|
3
.idea/modules/plugins-cloud.iml
generated
3
.idea/modules/plugins-cloud.iml
generated
@ -23,6 +23,9 @@
|
||||
<root url="jar://$GRADLE_REPOSITORY$/org.jclouds/jclouds-scriptbuilder/jars/jclouds-scriptbuilder-1.0-beta-4.jar!/" />
|
||||
<root url="jar://$GRADLE_REPOSITORY$/org.jclouds/jclouds-blobstore/jars/jclouds-blobstore-1.0-beta-4.jar!/" />
|
||||
<root url="jar://$GRADLE_REPOSITORY$/org.jclouds/jclouds-core/jars/jclouds-core-1.0-beta-4.jar!/" />
|
||||
<root url="jar://$GRADLE_REPOSITORY$/org.apache.httpcomponents/httpcore/jars/httpcore-4.1-alpha1.jar!/" />
|
||||
<root url="jar://$GRADLE_REPOSITORY$/org.apache.httpcomponents/httpcore-nio/jars/httpcore-nio-4.1-alpha1.jar!/" />
|
||||
<root url="jar://$GRADLE_REPOSITORY$/org.jclouds/jclouds-httpnio/jars/jclouds-httpnio-1.0-beta-4.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="http://jclouds.rimuhosting.com/apidocs/" />
|
||||
|
@ -19,18 +19,18 @@
|
||||
|
||||
package org.elasticsearch.util.logging;
|
||||
|
||||
import org.elasticsearch.util.gcommon.collect.Lists;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.util.Classes;
|
||||
import org.elasticsearch.util.gcommon.collect.Lists;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.util.gcommon.collect.Lists.*;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.elasticsearch.util.gcommon.collect.Lists.*;
|
||||
|
||||
/**
|
||||
* A set of utilities around Logging.
|
||||
@ -62,6 +62,10 @@ public class Loggers {
|
||||
}
|
||||
|
||||
public static ESLogger getLogger(Class clazz, Settings settings, String... prefixes) {
|
||||
return getLogger(getLoggerName(clazz), settings, prefixes);
|
||||
}
|
||||
|
||||
public static ESLogger getLogger(String loggerName, Settings settings, String... prefixes) {
|
||||
List<String> prefixesList = newArrayList();
|
||||
if (settings.getAsBoolean("logger.logHostAddress", false)) {
|
||||
try {
|
||||
@ -84,7 +88,7 @@ public class Loggers {
|
||||
if (prefixes != null && prefixes.length > 0) {
|
||||
prefixesList.addAll(asList(prefixes));
|
||||
}
|
||||
return getLogger(getLoggerName(clazz), prefixesList.toArray(new String[prefixesList.size()]));
|
||||
return getLogger(getLoggerName(loggerName), prefixesList.toArray(new String[prefixesList.size()]));
|
||||
}
|
||||
|
||||
public static ESLogger getLogger(ESLogger parentLogger, String s) {
|
||||
|
@ -30,13 +30,20 @@ configurations {
|
||||
|
||||
repositories {
|
||||
mavenRepo urls: "http://jclouds.googlecode.com/svn/repo"
|
||||
mavenRepo urls: "http://jclouds.rimuhosting.com/maven2/snapshots"
|
||||
mavenRepo urls: "http://java-xmlbuilder.googlecode.com/svn/repo"
|
||||
}
|
||||
|
||||
jcloudsVersion = "1.0-beta-4"
|
||||
|
||||
dependencies {
|
||||
compile project(':elasticsearch')
|
||||
compile('org.jclouds:jclouds-aws:1.0-beta-4')
|
||||
distLib('org.jclouds:jclouds-aws:1.0-beta-4')
|
||||
compile("org.jclouds:jclouds-httpnio:$jcloudsVersion")
|
||||
compile("org.jclouds:jclouds-blobstore:$jcloudsVersion")
|
||||
compile("org.jclouds:jclouds-aws:$jcloudsVersion")
|
||||
distLib("org.jclouds:jclouds-httpnio:$jcloudsVersion")
|
||||
distLib("org.jclouds:jclouds-blobstore:$jcloudsVersion")
|
||||
distLib("org.jclouds:jclouds-aws:$jcloudsVersion")
|
||||
|
||||
testCompile project(':test-testng')
|
||||
testCompile('org.testng:testng:5.10:jdk15') { transitive = false }
|
||||
|
@ -20,6 +20,7 @@
|
||||
package org.elasticsearch.cloud.blobstore;
|
||||
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.cloud.jclouds.JCloudsUtils;
|
||||
import org.elasticsearch.util.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.util.guice.inject.Inject;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
@ -57,7 +58,7 @@ public class CloudBlobStoreService extends AbstractLifecycleComponent<CloudBlobS
|
||||
String key = componentSettings.get("key", settings.get("cloud.key"));
|
||||
|
||||
if (type != null) {
|
||||
blobStoreContext = new BlobStoreContextFactory().createContext(type, account, key);
|
||||
blobStoreContext = new BlobStoreContextFactory().createContext(type, account, key, JCloudsUtils.buildModules(settings));
|
||||
logger.info("Connected to [{}] blob store service");
|
||||
} else {
|
||||
blobStoreContext = null;
|
||||
|
@ -20,6 +20,7 @@
|
||||
package org.elasticsearch.cloud.compute;
|
||||
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.cloud.jclouds.JCloudsUtils;
|
||||
import org.elasticsearch.util.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.util.guice.inject.Inject;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
@ -57,7 +58,7 @@ public class CloudComputeService extends AbstractLifecycleComponent<CloudCompute
|
||||
String key = componentSettings.get("key", settings.get("cloud.key"));
|
||||
|
||||
if (type != null) {
|
||||
computeServiceContext = new ComputeServiceContextFactory().createContext(type, account, key);
|
||||
computeServiceContext = new ComputeServiceContextFactory().createContext(type, account, key, JCloudsUtils.buildModules(settings));
|
||||
logger.info("Connected to [{}] compute service");
|
||||
} else {
|
||||
computeServiceContext = null;
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.cloud.jclouds;
|
||||
|
||||
import com.google.inject.Module;
|
||||
import org.elasticsearch.cloud.jclouds.logging.JCloudsLoggingModule;
|
||||
import org.elasticsearch.util.gcommon.collect.ImmutableList;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class JCloudsUtils {
|
||||
|
||||
public static Iterable<? extends Module> buildModules(Settings settings) {
|
||||
return ImmutableList.of(new JCloudsLoggingModule(settings));
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.cloud.jclouds.logging;
|
||||
|
||||
import org.elasticsearch.util.logging.ESLogger;
|
||||
import org.elasticsearch.util.logging.Loggers;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
import org.jclouds.logging.BaseLogger;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.config.LoggingModule;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class JCloudsLoggingModule extends LoggingModule {
|
||||
|
||||
private final Settings settings;
|
||||
|
||||
public JCloudsLoggingModule(Settings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override public Logger.LoggerFactory createLoggerFactory() {
|
||||
return new Logger.LoggerFactory() {
|
||||
@Override public Logger getLogger(String s) {
|
||||
return new JCloudsESLogger(Loggers.getLogger(s.replace("org.jclouds", "cloud.jclouds"), settings));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static class JCloudsESLogger extends BaseLogger {
|
||||
|
||||
private final ESLogger logger;
|
||||
|
||||
private JCloudsESLogger(ESLogger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override protected void logError(String s, Throwable throwable) {
|
||||
logger.error(s, throwable);
|
||||
}
|
||||
|
||||
@Override protected void logError(String s) {
|
||||
logger.error(s);
|
||||
}
|
||||
|
||||
@Override protected void logWarn(String s, Throwable throwable) {
|
||||
logger.warn(s, throwable);
|
||||
}
|
||||
|
||||
@Override protected void logWarn(String s) {
|
||||
logger.warn(s);
|
||||
}
|
||||
|
||||
@Override protected void logInfo(String s) {
|
||||
logger.info(s);
|
||||
}
|
||||
|
||||
@Override protected void logDebug(String s) {
|
||||
logger.debug(s);
|
||||
}
|
||||
|
||||
@Override protected void logTrace(String s) {
|
||||
logger.trace(s);
|
||||
}
|
||||
|
||||
@Override public String getCategory() {
|
||||
return logger.getName();
|
||||
}
|
||||
|
||||
@Override public boolean isTraceEnabled() {
|
||||
return logger.isTraceEnabled();
|
||||
}
|
||||
|
||||
@Override public boolean isDebugEnabled() {
|
||||
return logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override public boolean isInfoEnabled() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
|
||||
@Override public boolean isWarnEnabled() {
|
||||
return logger.isWarnEnabled();
|
||||
}
|
||||
|
||||
@Override public boolean isErrorEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user