-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Implementado SFL4J-API como Logger
- Foram corrigido alguns métodos e documentação. - Adicionado SimpleLogger.java como alternativa caso não encontre a classe StaticLoggerBinder
- Loading branch information
1 parent
781039e
commit d5f4da7
Showing
10 changed files
with
518 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/me/skiincraft/api/paladins/internal/logging/PaladinsLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package me.skiincraft.api.paladins.internal.logging; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.ServiceLoader; | ||
|
||
public class PaladinsLogger { | ||
|
||
private static PaladinsLogger instance; | ||
private static final Map<String, Logger> simpleLoggers = new HashMap<>(); | ||
private static boolean SLFJ4_ENABLED; | ||
|
||
private PaladinsLogger() { | ||
boolean found = false; | ||
try { | ||
Class.forName("org.slf4j.impl.StaticLoggerBinder"); | ||
found = true; | ||
} catch (ClassNotFoundException impl){ | ||
try { | ||
Class<?> serviceProviderClass = Class.forName("org.slf4j.spi.SLF4JServiceProvider"); | ||
found = ServiceLoader.load(serviceProviderClass).iterator().hasNext(); | ||
} catch (ClassNotFoundException spi){ | ||
lockAndWaitForWarning(); | ||
} | ||
} | ||
SLFJ4_ENABLED = found; | ||
} | ||
|
||
private void lockAndWaitForWarning(){ | ||
try { | ||
LoggerFactory.getLogger(PaladinsLogger.class); | ||
Thread.sleep(2500); | ||
} catch (Exception ignored){} | ||
} | ||
|
||
public Logger getLoggerInstance(String name){ | ||
if (SLFJ4_ENABLED) | ||
return LoggerFactory.getLogger(name); | ||
|
||
synchronized (simpleLoggers) { | ||
return simpleLoggers.computeIfAbsent(name, SimpleLogger::new); | ||
} | ||
} | ||
|
||
public Logger getLoggerInstance(Class<?> clazz){ | ||
if (SLFJ4_ENABLED) | ||
return LoggerFactory.getLogger(clazz); | ||
|
||
synchronized (simpleLoggers) { | ||
return simpleLoggers.computeIfAbsent(clazz.getSimpleName(), SimpleLogger::new); | ||
} | ||
} | ||
|
||
public static Logger getLogger(String name){ | ||
return getInstance().getLoggerInstance(name); | ||
} | ||
|
||
public static Logger getLogger(Class<?> clazz){ | ||
return getInstance().getLoggerInstance(clazz); | ||
} | ||
|
||
public static PaladinsLogger getInstance() { | ||
if (instance == null) { | ||
instance = new PaladinsLogger(); | ||
return instance; | ||
} | ||
return instance; | ||
} | ||
} |
Oops, something went wrong.