Skip to content

Commit

Permalink
have gone back to explicitly using Log4J in the gate.Utils.logOnce() …
Browse files Browse the repository at this point in the history
…method so that plugins built against an old version of GATE still work. closes #123
  • Loading branch information
greenwoodma committed Jan 20, 2021
1 parent 4ef1a5d commit 66d6845
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
13 changes: 11 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,21 @@
breaking existing code. Over time we should replace the legacy
code and then remove this dependency, or at least change the
scope to runtime to avoid breaking plugins which assume it
is available via the main GATE classloader -->
is available via the main GATE classloader.
Note that in order to remove this we would need to also remove
the gate.Utils.logOnce() method. I did wonder about changing the
params to use Object instead of Logger and then access via reflection
but that changes the method signature meaning plugins compiled against
previous versions can't see the method at all and hence throw a
NoSuchMethodError. Basically to fully remove this we need to
update all the plugins to use SLF4J instead of Log4J (sigh).
-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
<scope>compile</scope>
</dependency>

<!-- some of our dependencies use commons-logging, but we exclude those
Expand Down
33 changes: 11 additions & 22 deletions src/main/java/gate/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -763,28 +763,17 @@ public static RunningStrategy getRunningStrategy(Controller controller,
* @deprecated Log4J support will be removed in future, please use SLF4J
*/
@Deprecated
public static void logOnce (Logger logger, Object level, String message) {
if(!alreadyLoggedMessages.contains(message)) {
switch (level.toString()) {
case "TRACE":
logger.trace(message);
break;
case "DEBUG":
logger.debug(message);
break;
case "INFO":
logger.info(message);
break;
case "WARN":
logger.warn(message);
break;
case "ERROR":
case "FATAL":
logger.error(message);
break;
default:
// unknown log level, should be impossible
}
public static void logOnce (org.apache.log4j.Logger logger, org.apache.log4j.Level level, String message) {
if(!alreadyLoggedMessages.contains(message)) {

try {
logger.log(level, message);
} catch (Exception e) {
System.err.println(
"Failed to access logger through deprecated gate.Utils.logOnce method.\n"+
"Log message was: " + message);
}

alreadyLoggedMessages.add(message);
}
}
Expand Down

0 comments on commit 66d6845

Please sign in to comment.