Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pluggable logging for #426 v2 #476

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions archaius2-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.netflix.archaius</groupId>
<artifactId>archaius2-core</artifactId>
<version>2.1.11</version>
<dependencies>
<dependency>
<groupId>com.netflix.archaius</groupId>
<artifactId>archaius2-api</artifactId>
<version>2.1.11</version>
<scope>runtime</scope>
</dependency>
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
<scope>runtime</scope>
</dependency>
-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<name>archaius2-core</name>
<description>archaius2-core</description>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>netflixgithub</id>
<name>Netflix Open Source Development</name>
<email>[email protected]</email>
</developer>
</developers>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<url>https://github.com/Netflix/archaius</url>
<scm>
<url>https://github.com/Netflix/archaius.git</url>
</scm>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import com.netflix.archaius.interpolate.ConfigStrLookup;
import com.netflix.archaius.readers.PropertiesConfigReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.archaius.log.ArchaiusLogger;
import com.netflix.archaius.log.ArchaiusLoggerFactory;

import java.io.File;
import java.net.MalformedURLException;
Expand All @@ -49,7 +49,7 @@
*/
public class DefaultConfigLoader implements ConfigLoader {

private static final Logger LOG = LoggerFactory.getLogger(DefaultConfigLoader.class);
private static final ArchaiusLogger LOG = ArchaiusLoggerFactory.getLogger(DefaultConfigLoader.class);

private static final NoCascadeStrategy DEFAULT_CASCADE_STRATEGY = new NoCascadeStrategy();
private static final Lookup DEFAULT_LOOKUP = new Lookup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.archaius.log.ArchaiusLogger;
import com.netflix.archaius.log.ArchaiusLoggerFactory;

import com.netflix.archaius.api.Config;
import com.netflix.archaius.api.ConfigListener;
Expand All @@ -46,7 +46,7 @@
* TODO: Combine children and lookup into a single LinkedHashMap
*/
public class DefaultCompositeConfig extends AbstractConfig implements com.netflix.archaius.api.config.CompositeConfig {
private static final Logger LOG = LoggerFactory.getLogger(DefaultCompositeConfig.class);
private static final ArchaiusLogger LOG = ArchaiusLoggerFactory.getLogger(DefaultCompositeConfig.class);

/**
* The builder provides a fluent style API to create a CompositeConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import com.netflix.archaius.api.config.PollingStrategy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.archaius.log.ArchaiusLogger;
import com.netflix.archaius.log.ArchaiusLoggerFactory;

import com.netflix.archaius.config.polling.PollingResponse;

Expand All @@ -38,7 +38,7 @@
*
*/
public class PollingDynamicConfig extends AbstractConfig {
private static final Logger LOG = LoggerFactory.getLogger(PollingDynamicConfig.class);
private static final ArchaiusLogger LOG = ArchaiusLoggerFactory.getLogger(PollingDynamicConfig.class);

private volatile Map<String, String> current = new HashMap<String, String>();
private final AtomicBoolean busy = new AtomicBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.archaius.log.ArchaiusLogger;
import com.netflix.archaius.log.ArchaiusLoggerFactory;

import com.netflix.archaius.api.config.PollingStrategy;
import com.netflix.archaius.util.Futures;
import com.netflix.archaius.util.ThreadFactories;

public class FixedPollingStrategy implements PollingStrategy {
private static final Logger LOG = LoggerFactory.getLogger(FixedPollingStrategy.class);
private static final ArchaiusLogger LOG = ArchaiusLoggerFactory.getLogger(FixedPollingStrategy.class);
private final ScheduledExecutorService executor;
private final long interval;
private final TimeUnit units;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.netflix.archaius.log;

public interface ArchaiusLogger {

public abstract boolean isTraceEnabled();

public abstract void trace(String message);

public abstract void trace(String message, Object... params);

public abstract void trace(String message, Throwable error);

public abstract boolean isDebugEnabled();

public abstract void debug(String message);

public abstract void debug(String message, Object... params);

public abstract void debug(String message, Throwable error);

public abstract void info(String message);

public abstract void info(String message, Object... params);

public abstract void info(String message, Throwable error);

public abstract boolean isWarnEnabled();

public abstract void warn(String message);

public abstract void warn(String message, Object... params);

public abstract void warn(String message, Throwable error);

public abstract void error(String message);

public abstract void error(String message, Object... params);

public abstract void error(String message, Throwable error);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.netflix.archaius.log;


public class ArchaiusLoggerFactory {

private static volatile ArchaiusLoggerService service = new NoOpLoggerFactory();

public static ArchaiusLogger getLogger(
Class<?> clazz) {
return service.getLogger(clazz);
}

public static void setLoggerService(final ArchaiusLoggerService s) {
service = s;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.netflix.archaius.log;

public interface ArchaiusLoggerService {

public ArchaiusLogger getLogger(
Class<?> clazz);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.netflix.archaius.log;

public class NoOpLoggerFactory implements ArchaiusLoggerService {

@Override
public ArchaiusLogger getLogger(
Class<?> clazz) {
return logger;
}

private static ArchaiusLogger logger = new NoOpLogger();

private static class NoOpLogger implements ArchaiusLogger {

@Override
public boolean isTraceEnabled() {
return false;
}

@Override
public void trace(
String message) {
}

@Override
public void trace(
String message,
Object... params) {
}

@Override
public void trace(
String message,
Throwable error) {
}

@Override
public boolean isDebugEnabled() {
return false;
}

@Override
public void debug(
String message) {
}

@Override
public void debug(
String message,
Object... params) {
}

@Override
public void debug(
String message,
Throwable error) {
}

@Override
public void info(
String message) {
}

@Override
public void info(
String message,
Object... params) {
}

@Override
public void info(
String message,
Throwable error) {
}

@Override
public boolean isWarnEnabled() {
return false;
}

@Override
public void warn(
String message) {
}

@Override
public void warn(
String message,
Object... params) {
}

@Override
public void warn(
String message,
Throwable error) {
}

@Override
public void error(
String message) {
}

@Override
public void error(
String message,
Object... params) {
}

@Override
public void error(
String message,
Throwable error) {
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.netflix.archaius.api.PropertyListener;
import com.netflix.archaius.property.ListenerManager.ListenerUpdater;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.archaius.log.ArchaiusLogger;
import com.netflix.archaius.log.ArchaiusLoggerFactory;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand All @@ -47,7 +47,7 @@
*
*/
public class DefaultPropertyContainer implements PropertyContainer {
private final Logger LOG = LoggerFactory.getLogger(DefaultPropertyContainer.class);
private final ArchaiusLogger LOG = ArchaiusLoggerFactory.getLogger(DefaultPropertyContainer.class);

enum Type {
INTEGER (int.class, Integer.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.archaius.log.ArchaiusLogger;
import com.netflix.archaius.log.ArchaiusLoggerFactory;

public class JDCConfigReader implements Callable<Map<String, Object>> {

private static Logger log = LoggerFactory.getLogger(JDCConfigReader.class);
private static ArchaiusLogger log = ArchaiusLoggerFactory.getLogger(JDCConfigReader.class);

// The datasource to connect to the database.
private DataSource datasource;
Expand Down
Loading