Skip to content

Commit

Permalink
Convert SLF4j to JUL ... :-(
Browse files Browse the repository at this point in the history
  • Loading branch information
jdillon committed Jun 10, 2017
1 parent 65476cd commit 54c2e55
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 39 deletions.
6 changes: 0 additions & 6 deletions style/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
<artifactId>jline-terminal</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down
29 changes: 20 additions & 9 deletions style/src/main/java/org/jline/style/MemoryStyleSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

/**
Expand All @@ -27,7 +26,7 @@
public class MemoryStyleSource
implements StyleSource
{
private static final Logger log = LoggerFactory.getLogger(MemoryStyleSource.class);
private static final Logger log = Logger.getLogger(MemoryStyleSource.class.getName());

private final Map<String,Map<String,String>> backing = new ConcurrentHashMap<>();

Expand All @@ -39,7 +38,11 @@ public String get(final String group, final String name) {
if (styles != null) {
style = styles.get(name);
}
log.trace("Get: [{}] {} -> {}", group, name, style);

if (log.isLoggable(Level.FINEST)) {
log.finest(String.format("Get: [%s] %s -> %s", group, name, style));
}

return style;
}

Expand All @@ -49,14 +52,19 @@ public void set(final String group, final String name, final String style) {
requireNonNull(name);
requireNonNull(style);
backing.computeIfAbsent(group, k -> new ConcurrentHashMap<>()).put(name, style);
log.trace("Set: [{}] {} -> {}", group, name, style);

if (log.isLoggable(Level.FINEST)) {
log.finest(String.format("Set: [%s] %s -> %s", group, name, style));
}
}

@Override
public void remove(final String group) {
requireNonNull(group);
if (backing.remove(group) != null) {
log.trace("Removed: [{}]");
if (log.isLoggable(Level.FINEST)) {
log.finest(String.format("Removed: [%s]", group));
}
}
}

Expand All @@ -67,14 +75,17 @@ public void remove(final String group, final String name) {
Map<String,String> styles = backing.get(group);
if (styles != null) {
styles.remove(name);
log.trace("Removed: [{}] {}", group, name);

if (log.isLoggable(Level.FINEST)) {
log.finest(String.format("Removed: [%s] %s", group, name));
}
}
}

@Override
public void clear() {
backing.clear();
log.trace("Cleared");
log.finest("Cleared");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nullable;

Expand All @@ -19,8 +21,6 @@
import org.jline.style.StyleBundle.StyleName;
import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

Expand All @@ -33,7 +33,7 @@
class StyleBundleInvocationHandler
implements InvocationHandler
{
private static final Logger log = LoggerFactory.getLogger(StyleBundleInvocationHandler.class);
private static final Logger log = Logger.getLogger(StyleBundleInvocationHandler.class.getName());

private final Class<? extends StyleBundle> type;

Expand All @@ -59,7 +59,9 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg

// resolve the sourced-style, or use the default
String style = resolver.getSource().get(resolver.getGroup(), styleName);
log.trace("Sourced-style: {} -> {}", styleName, style);
if (log.isLoggable(Level.FINEST)) {
log.finest(String.format("Sourced-style: %s -> %s", styleName, style));
}

if (style == null) {
style = getDefaultStyle(method);
Expand All @@ -71,7 +73,9 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg
}

String value = String.valueOf(args[0]);
log.trace("Applying style: {} -> {} to: {}", styleName, style, value);
if (log.isLoggable(Level.FINEST)) {
log.finest(String.format("Applying style: %s -> %s to: %s", styleName, style, value));
}

AttributedStyle astyle = resolver.resolve(style);
return new AttributedString(value, astyle);
Expand Down Expand Up @@ -153,7 +157,9 @@ static <T extends StyleBundle> T create(final StyleResolver resolver, final Clas
requireNonNull(resolver);
requireNonNull(type);

log.trace("Using style-group: {} for type: {}", resolver.getGroup(), type.getName());
if (log.isLoggable(Level.FINEST)) {
log.finest(String.format("Using style-group: %s for type: %s", resolver.getGroup(), type.getName()));
}

StyleBundleInvocationHandler handler = new StyleBundleInvocationHandler(type, resolver);
return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, handler);
Expand Down
40 changes: 26 additions & 14 deletions style/src/main/java/org/jline/style/StyleResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
package org.jline.style;

import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nullable;

import org.jline.utils.AttributedStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;
import static org.jline.utils.AttributedStyle.*;
Expand All @@ -28,7 +28,7 @@
*/
public class StyleResolver
{
private static final Logger log = LoggerFactory.getLogger(StyleResolver.class);
private static final Logger log = Logger.getLogger(StyleResolver.class.getName());

private final StyleSource source;

Expand Down Expand Up @@ -57,7 +57,9 @@ public String getGroup() {
public AttributedStyle resolve(final String spec) {
requireNonNull(spec);

log.trace("Resolve: {}", spec);
if (log.isLoggable(Level.FINEST)) {
log.finest("Resolve: " + spec);
}

int i = spec.indexOf(":-");
if (i != -1) {
Expand All @@ -76,7 +78,9 @@ public AttributedStyle resolve(final String spec) {
public AttributedStyle resolve(final String spec, @Nullable final String defaultSpec) {
requireNonNull(spec);

log.trace("Resolve: {}; default: {}", spec, defaultSpec);
if (log.isLoggable(Level.FINEST)) {
log.finest(String.format("Resolve: %s; default: %s", spec, defaultSpec));
}

AttributedStyle style = apply(DEFAULT, spec);
if (style == DEFAULT && defaultSpec != null) {
Expand All @@ -89,7 +93,9 @@ public AttributedStyle resolve(final String spec, @Nullable final String default
* Apply style specification.
*/
private AttributedStyle apply(AttributedStyle style, final String spec) {
log.trace("Apply: {}", spec);
if (log.isLoggable(Level.FINEST)) {
log.finest("Apply: " + spec);
}

for (String item : spec.split(",")) {
item = item.trim();
Expand All @@ -115,10 +121,12 @@ else if (item.contains(":")) {
* Apply source-referenced named style.
*/
private AttributedStyle applyReference(final AttributedStyle style, final String spec) {
log.trace("Apply-reference: {}", spec);
if (log.isLoggable(Level.FINEST)) {
log.finest("Apply-reference: " + spec);
}

if (spec.length() == 1) {
log.warn("Invalid style-reference; missing discriminator: {}", spec);
log.warning("Invalid style-reference; missing discriminator: " + spec);
}
else {
String name = spec.substring(1, spec.length());
Expand All @@ -136,7 +144,9 @@ private AttributedStyle applyReference(final AttributedStyle style, final String
* Apply default named styles.
*/
private AttributedStyle applyNamed(final AttributedStyle style, final String name) {
log.trace("Apply-named: {}", name);
if (log.isLoggable(Level.FINEST)) {
log.finest("Apply-named: " + name);
}

// TODO: consider short aliases for named styles

Expand Down Expand Up @@ -177,7 +187,7 @@ private AttributedStyle applyNamed(final AttributedStyle style, final String nam
return style.hidden();

default:
log.warn("Unknown style: {}", name);
log.warning("Unknown style: " + name);
return style;
}
}
Expand All @@ -188,7 +198,9 @@ private AttributedStyle applyNamed(final AttributedStyle style, final String nam
* @param spec Color specification: {@code <color-mode>:<color-name>}
*/
private AttributedStyle applyColor(final AttributedStyle style, final String spec) {
log.trace("Apply-color: {}", spec);
if (log.isLoggable(Level.FINEST)) {
log.finest("Apply-color: " + spec);
}

// extract color-mode:color-name
String[] parts = spec.split(":", 2);
Expand All @@ -198,7 +210,7 @@ private AttributedStyle applyColor(final AttributedStyle style, final String spe
// resolve the color-name
Integer color = color(colorName);
if (color == null) {
log.warn("Invalid color-name: {}", colorName);
log.warning("Invalid color-name: " + colorName);
}
else {
// resolve and apply color-mode
Expand All @@ -214,7 +226,7 @@ private AttributedStyle applyColor(final AttributedStyle style, final String spe
return style.background(color);

default:
log.warn("Invalid color-mode: {}", colorMode);
log.warning("Invalid color-mode: " + colorMode);
}
}
return style;
Expand Down Expand Up @@ -252,7 +264,7 @@ else if (name.charAt(0) == '~') {
return color.code;
}
catch (IllegalArgumentException e) {
log.warn("Invalid style-color name: {}", name);
log.warning("Invalid style-color name: " + name);
return null;
}
}
Expand Down
12 changes: 8 additions & 4 deletions style/src/main/java/org/jline/style/Styler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/
package org.jline.style;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.jline.style.StyleBundle.StyleGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

Expand All @@ -24,7 +25,7 @@
*/
public class Styler
{
private static final Logger log = LoggerFactory.getLogger(Styler.class);
private static final Logger log = Logger.getLogger(Styler.class.getName());

private static volatile StyleSource source = new NopStyleSource();

Expand All @@ -37,7 +38,10 @@ private Styler() {
*/
public static void setSource(final StyleSource source) {
Styler.source = requireNonNull(source);
log.debug("Source: {}", source);

if (log.isLoggable(Level.FINE)) {
log.fine("Source: " + source);
}
}

/**
Expand Down

0 comments on commit 54c2e55

Please sign in to comment.