Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SECF-5700: Start using log4j core&api and support logging to stdout #976

Open
wants to merge 1 commit into
base: Ursa-21.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions sources/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,14 @@
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
</exclusions>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.24.0</version>
</dependency>

<!-- JUnit for testing -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract public class KalturaLogger
// Creation & retrieval methods:
public static IKalturaLogger getLogger(String name)
{
return KalturaLoggerLog4j.get(name);
return new KalturaLoggerLog4j(name);
}

public static IKalturaLogger getLogger(Class<?> clazz)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,67 @@
// ===================================================================================================
package com.kaltura.client;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
import org.apache.logging.log4j.LogManager;

public class KalturaLoggerLog4j extends Logger implements IKalturaLogger
{
protected Logger logger;
static protected LoggerFactory loggerFactory = new KalturaLoggerFactory();

static class KalturaLoggerFactory implements LoggerFactory {
@Override
public Logger makeNewLoggerInstance(String name) {
return new KalturaLoggerLog4j(name);
}
}

// Creation & retrieval methods:
public static IKalturaLogger get(String name)
{
Logger logger = LogManager.getLogger(name, loggerFactory);
if(logger instanceof Logger){
return (KalturaLoggerLog4j) logger;
}

return null;
}

protected KalturaLoggerLog4j(String name)
private org.apache.logging.log4j.Logger logger;

public KalturaLoggerLog4j(String name)
{
super(name);
logger = LogManager.getLogger(name);
}

@Override
public boolean isEnabled() {
return this.isInfoEnabled();
return logger.isInfoEnabled();
}
@Override
public void trace(Object message) {
logger.trace(message);
}
@Override
public void debug(Object message) {
logger.debug(message);
}
@Override
public void info(Object message) {
logger.info(message);
}
@Override
public void warn(Object message) {
logger.warn(message);
}
@Override
public void error(Object message) {
logger.error(message);
}
@Override
public void fatal(Object message) {
logger.fatal(message);
}
@Override
public void trace(Object message, Throwable t) {
logger.trace(message, t);
}
@Override
public void debug(Object message, Throwable t) {
logger.debug(message, t);
}
@Override
public void info(Object message, Throwable t) {
logger.info(message, t);
}
@Override
public void warn(Object message, Throwable t) {
logger.warn(message, t);
}
@Override
public void error(Object message, Throwable t) {
logger.error(message, t);
}
@Override
public void fatal(Object message, Throwable t) {
logger.fatal(message, t);
}
}
13 changes: 13 additions & 0 deletions sources/java/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS}: %-5level{lowerCase=true} - %msg%n%n" />
</Console>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>