Skip to content

Commit

Permalink
style(prettier): prettified code
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette authored and actions-user committed Aug 13, 2021
1 parent 86b60b9 commit 1e4d9d4
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.github.arthurfiorette.sinklibrary.logging;

import com.github.arthurfiorette.sinklibrary.component.Component;

import org.bukkit.ChatColor;

public interface BaseLogger extends Component {
void log(final Level level, final Class<?> author, final String message, final Object... args);

void log(final Level level, final Class<?> author, final String message,
final Throwable throwable);
void log(
final Level level,
final Class<?> author,
final String message,
final Throwable throwable
);

default void log(final Level level, final String message, final Object... args) {
this.log(level, this.getBasePlugin().getClass(), message, args);
Expand Down Expand Up @@ -128,9 +131,20 @@ default void trace(final String message, final Throwable throwable) {

// Default formatting

static String format(final Level level, final Class<?> author, final String message,
final Object... args) {
return "[" + author.getClass().getSimpleName() + "] (" + level.toColorUpperCase()
+ ChatColor.RESET + ") " + String.format(message, args);
static String format(
final Level level,
final Class<?> author,
final String message,
final Object... args
) {
return (
"[" +
author.getClass().getSimpleName() +
"] (" +
level.toColorUpperCase() +
ChatColor.RESET +
") " +
String.format(message, args)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.github.arthurfiorette.sinklibrary.logging;

import com.github.arthurfiorette.sinklibrary.core.BasePlugin;

import org.bukkit.Bukkit;

import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;

@RequiredArgsConstructor
public class ConsoleLogger implements BaseLogger {
Expand All @@ -22,13 +20,16 @@ public void log(
final String message,
final Object... args
) {
Bukkit
.getConsoleSender()
.sendMessage(BaseLogger.format(level, author, message, args));
Bukkit.getConsoleSender().sendMessage(BaseLogger.format(level, author, message, args));
}

@Override
public void log(final Level level, final Class<?> author, final String message, final Throwable throwable) {
public void log(
final Level level,
final Class<?> author,
final String message,
final Throwable throwable
) {
this.log(level, author, message);
for (final StackTraceElement trace : throwable.getStackTrace()) {
Bukkit.getConsoleSender().sendMessage(trace.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.arthurfiorette.sinklibrary.logging;

import com.github.arthurfiorette.sinklibrary.core.BasePlugin;

import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
Expand All @@ -13,24 +12,35 @@ public class FilteredConsoleLogger extends ConsoleLogger {
@NonNull
private Level maxLevel;

public FilteredConsoleLogger(@NonNull final BasePlugin basePlugin, @NonNull final Level maxLevel) {
public FilteredConsoleLogger(
@NonNull final BasePlugin basePlugin,
@NonNull final Level maxLevel
) {
super(basePlugin);
this.maxLevel = maxLevel;
}

@Override
public void log(final Level level, final Class<?> author, final String message,
final Object... args) {
public void log(
final Level level,
final Class<?> author,
final String message,
final Object... args
) {
if (this.maxLevel.isAtLeastAsSpecificAs(level)) {
super.log(level, author, message, args);
}
}

@Override
public void log(final Level level, final Class<?> author, final String message, final Throwable throwable) {
public void log(
final Level level,
final Class<?> author,
final String message,
final Throwable throwable
) {
if (this.maxLevel.isAtLeastAsSpecificAs(level)) {
super.log(level, author, message, throwable);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.arthurfiorette.sinklibrary.logging;

import com.github.arthurfiorette.sinklibrary.core.BasePlugin;

import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
Expand All @@ -13,21 +12,33 @@ public class FilteredMultipleLogger extends MultipleLogger {
@NonNull
private Level maxLevel;

public FilteredMultipleLogger(@NonNull final BasePlugin basePlugin, @NonNull final Level maxLevel) {
public FilteredMultipleLogger(
@NonNull final BasePlugin basePlugin,
@NonNull final Level maxLevel
) {
super(basePlugin);
this.maxLevel = maxLevel;
}

@Override
public void log(final Level level, final Class<?> author, final String message,
final Object... args) {
public void log(
final Level level,
final Class<?> author,
final String message,
final Object... args
) {
if (this.maxLevel.isAtLeastAsSpecificAs(level)) {
super.log(level, author, message, args);
}
}

@Override
public void log(final Level level, final Class<?> author, final String message, final Throwable throwable) {
public void log(
final Level level,
final Class<?> author,
final String message,
final Throwable throwable
) {
if (this.maxLevel.isAtLeastAsSpecificAs(level)) {
super.log(level, author, message, throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.Getter;
import lombok.NonNull;
import lombok.experimental.Accessors;

import org.bukkit.ChatColor;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.github.arthurfiorette.sinklibrary.core.BasePlugin;
import com.google.common.collect.Sets;

import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

@RequiredArgsConstructor
public class MultipleLogger implements BaseLogger {
Expand All @@ -25,20 +22,35 @@ public class MultipleLogger implements BaseLogger {
private Set<CommandSender> senders = Sets.newHashSet(Bukkit.getConsoleSender());

@Override
public void log(final Level level, final Class<?> author, final String message,
final Object... args) {
this.senders.stream().forEach(sender -> {
sender.sendMessage(BaseLogger.format(level, author, message, args));
});
public void log(
final Level level,
final Class<?> author,
final String message,
final Object... args
) {
this.senders.stream()
.forEach(
sender -> {
sender.sendMessage(BaseLogger.format(level, author, message, args));
}
);
}

@Override
public void log(final Level level, final Class<?> author, final String message, final Throwable throwable) {
this.senders.stream().forEach(sender -> {
sender.sendMessage(BaseLogger.format(level, author, message));
for(final StackTraceElement trace: throwable.getStackTrace()) {
sender.sendMessage(trace.toString());
}
});
public void log(
final Level level,
final Class<?> author,
final String message,
final Throwable throwable
) {
this.senders.stream()
.forEach(
sender -> {
sender.sendMessage(BaseLogger.format(level, author, message));
for (final StackTraceElement trace : throwable.getStackTrace()) {
sender.sendMessage(trace.toString());
}
}
);
}
}

0 comments on commit 1e4d9d4

Please sign in to comment.