-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 'bindings/java: Implement custom logger ' from Kim Seon Woo
## Purpose of the PR - As bindings/java is just a library, we shouldn't have to add specific library dependency(such as slf4j) to itself - In order to load bindings/java to 3rd party software(such as Datagrip), we shouldn't provide a library with slf4j included ## Changes - Remove slf4j, logback dependency and files - Add custom logger implementation ## ETC We can now connect to Datagrip(but there are some errors though)  ## Reference [Issue](#615) Closes #915
- Loading branch information
Showing
9 changed files
with
147 additions
and
25 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
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
14 changes: 14 additions & 0 deletions
14
bindings/java/src/main/java/org/github/tursodatabase/utils/Logger.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,14 @@ | ||
package org.github.tursodatabase.utils; | ||
|
||
/** A simple internal Logger interface. */ | ||
public interface Logger { | ||
void trace(String message, Object... params); | ||
|
||
void debug(String message, Object... params); | ||
|
||
void info(String message, Object... params); | ||
|
||
void warn(String message, Object... params); | ||
|
||
void error(String message, Object... params); | ||
} |
122 changes: 122 additions & 0 deletions
122
bindings/java/src/main/java/org/github/tursodatabase/utils/LoggerFactory.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,122 @@ | ||
package org.github.tursodatabase.utils; | ||
|
||
import java.util.logging.Level; | ||
|
||
/** | ||
* A factory for {@link Logger} instances that uses SLF4J if present, falling back on a | ||
* java.util.logging implementation otherwise. | ||
*/ | ||
public class LoggerFactory { | ||
static final boolean USE_SLF4J; | ||
|
||
static { | ||
boolean useSLF4J; | ||
try { | ||
Class.forName("org.slf4j.Logger"); | ||
useSLF4J = true; | ||
} catch (Exception e) { | ||
useSLF4J = false; | ||
} | ||
USE_SLF4J = useSLF4J; | ||
} | ||
|
||
/** | ||
* Get a {@link Logger} instance for the given host class. | ||
* | ||
* @param hostClass the host class from which log messages will be issued | ||
* @return a Logger | ||
*/ | ||
public static Logger getLogger(Class<?> hostClass) { | ||
if (USE_SLF4J) { | ||
return new SLF4JLogger(hostClass); | ||
} | ||
|
||
return new JDKLogger(hostClass); | ||
} | ||
|
||
private static class JDKLogger implements Logger { | ||
final java.util.logging.Logger logger; | ||
|
||
public JDKLogger(Class<?> hostClass) { | ||
logger = java.util.logging.Logger.getLogger(hostClass.getCanonicalName()); | ||
} | ||
|
||
@Override | ||
public void trace(String message, Object... params) { | ||
if (logger.isLoggable(Level.FINEST)) { | ||
logger.log(Level.FINEST, String.format(message, params)); | ||
} | ||
} | ||
|
||
@Override | ||
public void debug(String message, Object... params) { | ||
if (logger.isLoggable(Level.FINE)) { | ||
logger.log(Level.FINE, String.format(message, params)); | ||
} | ||
} | ||
|
||
@Override | ||
public void info(String message, Object... params) { | ||
if (logger.isLoggable(Level.INFO)) { | ||
logger.log(Level.INFO, String.format(message, params)); | ||
} | ||
} | ||
|
||
@Override | ||
public void warn(String message, Object... params) { | ||
if (logger.isLoggable(Level.WARNING)) { | ||
logger.log(Level.WARNING, String.format(message, params)); | ||
} | ||
} | ||
|
||
@Override | ||
public void error(String message, Object... params) { | ||
if (logger.isLoggable(Level.SEVERE)) { | ||
logger.log(Level.SEVERE, String.format(message, params)); | ||
} | ||
} | ||
} | ||
|
||
private static class SLF4JLogger implements Logger { | ||
final org.slf4j.Logger logger; | ||
|
||
SLF4JLogger(Class<?> hostClass) { | ||
logger = org.slf4j.LoggerFactory.getLogger(hostClass); | ||
} | ||
|
||
@Override | ||
public void trace(String message, Object... params) { | ||
if (logger.isTraceEnabled()) { | ||
logger.trace(message, String.format(message, params)); | ||
} | ||
} | ||
|
||
@Override | ||
public void debug(String message, Object... params) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug(message, String.format(message, params)); | ||
} | ||
} | ||
|
||
@Override | ||
public void info(String message, Object... params) { | ||
if (logger.isInfoEnabled()) { | ||
logger.info(message, String.format(message, params)); | ||
} | ||
} | ||
|
||
@Override | ||
public void warn(String message, Object... params) { | ||
if (logger.isWarnEnabled()) { | ||
logger.warn(message, String.format(message, params)); | ||
} | ||
} | ||
|
||
@Override | ||
public void error(String message, Object... params) { | ||
if (logger.isErrorEnabled()) { | ||
logger.error(message, String.format(message, params)); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.