mirror of
https://github.com/sismics/docs.git
synced 2024-11-24 06:37:56 +01:00
log4j -> logback
This commit is contained in:
parent
95e0b870f6
commit
97d6e8f528
@ -62,16 +62,6 @@
|
|||||||
<artifactId>jsoup</artifactId>
|
<artifactId>jsoup</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
@ -82,6 +72,21 @@
|
|||||||
<artifactId>jcl-over-slf4j</artifactId>
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jul-to-slf4j</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-to-slf4j</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>at.favre.lib</groupId>
|
<groupId>at.favre.lib</groupId>
|
||||||
<artifactId>bcrypt</artifactId>
|
<artifactId>bcrypt</artifactId>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package com.sismics.util.io;
|
package com.sismics.util.io;
|
||||||
|
|
||||||
import com.google.common.io.Closer;
|
import com.google.common.io.Closer;
|
||||||
import org.apache.log4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -15,7 +16,7 @@ import java.io.InputStreamReader;
|
|||||||
*/
|
*/
|
||||||
public class InputStreamReaderThread extends Thread {
|
public class InputStreamReaderThread extends Thread {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(InputStreamReaderThread.class);
|
private static final Logger logger = LoggerFactory.getLogger(InputStreamReaderThread.class);
|
||||||
|
|
||||||
private InputStream is;
|
private InputStream is;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.sismics.util.log4j;
|
package com.sismics.util.logback;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.Level;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log search criteria.
|
* Log search criteria.
|
@ -1,6 +1,7 @@
|
|||||||
package com.sismics.util.log4j;
|
package com.sismics.util.logback;
|
||||||
|
|
||||||
import org.apache.log4j.Level;
|
|
||||||
|
import ch.qos.logback.classic.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log entry.
|
* Log entry.
|
@ -1,25 +1,22 @@
|
|||||||
package com.sismics.util.log4j;
|
package com.sismics.util.logback;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.Level;
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import ch.qos.logback.core.AppenderBase;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.sismics.docs.core.util.jpa.PaginatedList;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
import org.apache.log4j.AppenderSkeleton;
|
|
||||||
import org.apache.log4j.Level;
|
|
||||||
import org.apache.log4j.helpers.LogLog;
|
|
||||||
import org.apache.log4j.spi.LoggingEvent;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.sismics.docs.core.util.jpa.PaginatedList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Memory appender for Log4J.
|
* Memory appender for Logback.
|
||||||
*
|
*
|
||||||
* @author jtremeaux
|
* @author jtremeaux
|
||||||
*/
|
*/
|
||||||
public class MemoryAppender extends AppenderSkeleton {
|
public class MemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum size of the queue.
|
* Maximum size of the queue.
|
||||||
@ -29,34 +26,18 @@ public class MemoryAppender extends AppenderSkeleton {
|
|||||||
/**
|
/**
|
||||||
* Queue of log entries.
|
* Queue of log entries.
|
||||||
*/
|
*/
|
||||||
private final Queue<LogEntry> logQueue = new ConcurrentLinkedQueue<LogEntry>();
|
private static final Queue<LogEntry> logQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean requiresLayout() {
|
protected void append(ILoggingEvent event) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void close() {
|
|
||||||
if (closed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
closed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void append(LoggingEvent event) {
|
|
||||||
while (logQueue.size() > size) {
|
while (logQueue.size() > size) {
|
||||||
logQueue.remove();
|
logQueue.remove();
|
||||||
}
|
}
|
||||||
if (closed) {
|
|
||||||
LogLog.warn("This appender is already closed, cannot append event.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String loggerName = getLoggerName(event);
|
String loggerName = getLoggerName(event);
|
||||||
|
|
||||||
LogEntry logEntry = new LogEntry(System.currentTimeMillis(), event.getLevel(), loggerName, event.getMessage().toString());
|
LogEntry logEntry = new LogEntry(System.currentTimeMillis(), event.getLevel(), loggerName, event.getMessage());
|
||||||
logQueue.add(logEntry);
|
logQueue.add(logEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +47,7 @@ public class MemoryAppender extends AppenderSkeleton {
|
|||||||
* @param event Event
|
* @param event Event
|
||||||
* @return Class name
|
* @return Class name
|
||||||
*/
|
*/
|
||||||
private String getLoggerName(LoggingEvent event) {
|
private String getLoggerName(ILoggingEvent event) {
|
||||||
int index = event.getLoggerName().lastIndexOf('.');
|
int index = event.getLoggerName().lastIndexOf('.');
|
||||||
|
|
||||||
return (index > -1) ?
|
return (index > -1) ?
|
||||||
@ -75,12 +56,12 @@ public class MemoryAppender extends AppenderSkeleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter of logList.
|
* Getter of size.
|
||||||
*
|
*
|
||||||
* @return logList
|
* @return size
|
||||||
*/
|
*/
|
||||||
public Queue<LogEntry> getLogList() {
|
public int getSize() {
|
||||||
return logQueue;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,15 +79,14 @@ public class MemoryAppender extends AppenderSkeleton {
|
|||||||
* @param criteria Search criteria
|
* @param criteria Search criteria
|
||||||
* @param list Paginated list (modified by side effect)
|
* @param list Paginated list (modified by side effect)
|
||||||
*/
|
*/
|
||||||
public void find(LogCriteria criteria, PaginatedList<LogEntry> list) {
|
public static void find(LogCriteria criteria, PaginatedList<LogEntry> list) {
|
||||||
List<LogEntry> logEntryList = new LinkedList<LogEntry>();
|
List<LogEntry> logEntryList = new LinkedList<LogEntry>();
|
||||||
final Level minLevel = criteria.getMinLevel();
|
final Level minLevel = criteria.getMinLevel();
|
||||||
final String tag = criteria.getTag();
|
final String tag = criteria.getTag();
|
||||||
final String message = criteria.getMessage();
|
final String message = criteria.getMessage();
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
for (Iterator<LogEntry> it = logQueue.iterator(); it.hasNext();) {
|
for (LogEntry logEntry : logQueue) {
|
||||||
LogEntry logEntry = it.next();
|
if ((minLevel == null || logEntry.getLevel().toInt() >= minLevel.toInt()) &&
|
||||||
if ((minLevel == null || Integer.compare(logEntry.getLevel().toInt(), minLevel.toInt()) >= 0) &&
|
|
||||||
(tag == null || logEntry.getTag().toLowerCase().equals(tag)) &&
|
(tag == null || logEntry.getTag().toLowerCase().equals(tag)) &&
|
||||||
(message == null || logEntry.getMessage().toLowerCase().contains(message))) {
|
(message == null || logEntry.getMessage().toLowerCase().contains(message))) {
|
||||||
logEntryList.add(logEntry);
|
logEntryList.add(logEntry);
|
@ -1,10 +0,0 @@
|
|||||||
log4j.rootCategory=DEBUG, CONSOLE, MEMORY
|
|
||||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %p %l %m %n
|
|
||||||
log4j.appender.MEMORY=com.sismics.util.log4j.MemoryAppender
|
|
||||||
log4j.appender.MEMORY.size=1000
|
|
||||||
|
|
||||||
log4j.logger.com.sismics=INFO
|
|
||||||
log4j.logger.org.hibernate=ERROR
|
|
||||||
log4j.logger.org.apache.directory=ERROR
|
|
18
docs-core/src/test/resources/logback.xml
Normal file
18
docs-core/src/test/resources/logback.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%date [%t] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
<appender name="MEMORY" class="com.sismics.util.logback.MemoryAppender">
|
||||||
|
<size>1000</size>
|
||||||
|
</appender>
|
||||||
|
<logger name="org.apache.directory" level="ERROR"/>
|
||||||
|
<logger name="com.sismics" level="INFO"/>
|
||||||
|
<logger name="org.hibernate" level="ERROR"/>
|
||||||
|
<root level="DEBUG">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="MEMORY"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
@ -48,11 +48,6 @@
|
|||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.servlet</groupId>
|
<groupId>jakarta.servlet</groupId>
|
||||||
<artifactId>jakarta.servlet-api</artifactId>
|
<artifactId>jakarta.servlet-api</artifactId>
|
||||||
@ -64,11 +59,6 @@
|
|||||||
<artifactId>joda-time</artifactId>
|
<artifactId>joda-time</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jul-to-slf4j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Test dependencies -->
|
<!-- Test dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
package com.sismics.util.filter;
|
package com.sismics.util.filter;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.Level;
|
||||||
|
import ch.qos.logback.classic.LoggerContext;
|
||||||
|
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import ch.qos.logback.core.rolling.RollingFileAppender;
|
||||||
|
import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy;
|
||||||
|
import ch.qos.logback.core.util.FileSize;
|
||||||
import com.sismics.docs.core.model.context.AppContext;
|
import com.sismics.docs.core.model.context.AppContext;
|
||||||
import com.sismics.docs.core.util.DirectoryUtil;
|
import com.sismics.docs.core.util.DirectoryUtil;
|
||||||
import com.sismics.docs.core.util.TransactionUtil;
|
import com.sismics.docs.core.util.TransactionUtil;
|
||||||
import com.sismics.util.EnvironmentUtil;
|
import com.sismics.util.EnvironmentUtil;
|
||||||
import com.sismics.util.context.ThreadLocalContext;
|
import com.sismics.util.context.ThreadLocalContext;
|
||||||
import com.sismics.util.jpa.EMF;
|
import com.sismics.util.jpa.EMF;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityTransaction;
|
||||||
import jakarta.servlet.*;
|
import jakarta.servlet.*;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.ws.rs.core.HttpHeaders;
|
import jakarta.ws.rs.core.HttpHeaders;
|
||||||
import org.apache.log4j.Level;
|
|
||||||
import org.apache.log4j.PatternLayout;
|
|
||||||
import org.apache.log4j.RollingFileAppender;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.bridge.SLF4JBridgeHandler;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
@ -48,18 +51,30 @@ public class RequestContextFilter implements Filter {
|
|||||||
|
|
||||||
|
|
||||||
// Initialize file logger
|
// Initialize file logger
|
||||||
RollingFileAppender fileAppender = new RollingFileAppender();
|
LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||||
fileAppender.setName("FILE");
|
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
|
||||||
fileAppender.setFile(DirectoryUtil.getLogDirectory().resolve("docs.log").toString());
|
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
|
||||||
fileAppender.setLayout(new PatternLayout("%d{DATE} %p %l %m %n"));
|
encoder.setContext(logContext);
|
||||||
fileAppender.setThreshold(Level.INFO);
|
encoder.setPattern("%date [%t] %-5level %logger{36} - %msg%n");
|
||||||
fileAppender.setAppend(true);
|
encoder.start();
|
||||||
fileAppender.setMaxFileSize("5MB");
|
SizeAndTimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new SizeAndTimeBasedRollingPolicy<>();
|
||||||
fileAppender.setMaxBackupIndex(5);
|
rollingPolicy.setMaxFileSize(FileSize.valueOf("5MB"));
|
||||||
fileAppender.activateOptions();
|
rollingPolicy.setFileNamePattern("docs.%d{yyyy-MM-dd_HH}.log");
|
||||||
org.apache.log4j.Logger.getRootLogger().addAppender(fileAppender);
|
rollingPolicy.setMaxHistory(5);
|
||||||
SLF4JBridgeHandler.removeHandlersForRootLogger();
|
rollingPolicy.setContext(logContext);
|
||||||
SLF4JBridgeHandler.install();
|
rollingPolicy.setParent(appender);
|
||||||
|
rollingPolicy.start();
|
||||||
|
appender.setContext(logContext);
|
||||||
|
appender.setName("FILE");
|
||||||
|
appender.setFile(DirectoryUtil.getLogDirectory().resolve("docs.log").toString());
|
||||||
|
appender.setEncoder(encoder);
|
||||||
|
appender.setRollingPolicy(rollingPolicy);
|
||||||
|
appender.setAppend(true);
|
||||||
|
appender.start();
|
||||||
|
ch.qos.logback.classic.Logger logger = logContext.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||||
|
logger.setAdditive(false);
|
||||||
|
logger.setLevel(Level.INFO);
|
||||||
|
logger.addAppender(appender);
|
||||||
|
|
||||||
// Initialize the application context
|
// Initialize the application context
|
||||||
TransactionUtil.handle(AppContext::getInstance);
|
TransactionUtil.handle(AppContext::getInstance);
|
||||||
|
@ -63,11 +63,6 @@
|
|||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>joda-time</groupId>
|
<groupId>joda-time</groupId>
|
||||||
<artifactId>joda-time</artifactId>
|
<artifactId>joda-time</artifactId>
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
log4j.rootCategory=WARN, CONSOLE, MEMORY
|
|
||||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %p %l %m %n
|
|
||||||
log4j.appender.MEMORY=com.sismics.util.log4j.MemoryAppender
|
|
||||||
log4j.appender.MEMORY.size=1000
|
|
||||||
|
|
||||||
log4j.logger.com.sismics=DEBUG
|
|
||||||
log4j.logger.org.apache.pdfbox=ERROR
|
|
||||||
log4j.logger.org.glassfish.jersey.servlet.WebComponent=ERROR
|
|
||||||
log4j.logger.org.apache.directory=ERROR
|
|
19
docs-web/src/dev/resources/logback.xml
Normal file
19
docs-web/src/dev/resources/logback.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%date [%t] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
<appender name="MEMORY" class="com.sismics.util.logback.MemoryAppender">
|
||||||
|
<size>1000</size>
|
||||||
|
</appender>
|
||||||
|
<logger name="org.apache.directory" level="ERROR"/>
|
||||||
|
<logger name="com.sismics" level="DEBUG"/>
|
||||||
|
<logger name="org.apache.pdfbox" level="ERROR"/>
|
||||||
|
<logger name="org.glassfish.jersey.servlet.WebComponent" level="ERROR"/>
|
||||||
|
<root level="WARN">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="MEMORY"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
@ -1,5 +1,6 @@
|
|||||||
package com.sismics.docs.rest.resource;
|
package com.sismics.docs.rest.resource;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.Level;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.sismics.docs.core.constant.ConfigType;
|
import com.sismics.docs.core.constant.ConfigType;
|
||||||
import com.sismics.docs.core.constant.Constants;
|
import com.sismics.docs.core.constant.Constants;
|
||||||
@ -23,9 +24,9 @@ import com.sismics.rest.exception.ServerException;
|
|||||||
import com.sismics.rest.util.ValidationUtil;
|
import com.sismics.rest.util.ValidationUtil;
|
||||||
import com.sismics.util.JsonUtil;
|
import com.sismics.util.JsonUtil;
|
||||||
import com.sismics.util.context.ThreadLocalContext;
|
import com.sismics.util.context.ThreadLocalContext;
|
||||||
import com.sismics.util.log4j.LogCriteria;
|
import com.sismics.util.logback.LogCriteria;
|
||||||
import com.sismics.util.log4j.LogEntry;
|
import com.sismics.util.logback.LogEntry;
|
||||||
import com.sismics.util.log4j.MemoryAppender;
|
import com.sismics.util.logback.MemoryAppender;
|
||||||
import jakarta.json.Json;
|
import jakarta.json.Json;
|
||||||
import jakarta.json.JsonArrayBuilder;
|
import jakarta.json.JsonArrayBuilder;
|
||||||
import jakarta.json.JsonObjectBuilder;
|
import jakarta.json.JsonObjectBuilder;
|
||||||
@ -34,8 +35,6 @@ import jakarta.persistence.Query;
|
|||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Appender;
|
|
||||||
import org.apache.log4j.Level;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -539,14 +538,6 @@ public class AppResource extends BaseResource {
|
|||||||
}
|
}
|
||||||
checkBaseFunction(BaseFunction.ADMIN);
|
checkBaseFunction(BaseFunction.ADMIN);
|
||||||
|
|
||||||
// Get the memory appender
|
|
||||||
org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger();
|
|
||||||
Appender appender = logger.getAppender("MEMORY");
|
|
||||||
if (!(appender instanceof MemoryAppender)) {
|
|
||||||
throw new ServerException("ServerError", "MEMORY appender not configured");
|
|
||||||
}
|
|
||||||
MemoryAppender memoryAppender = (MemoryAppender) appender;
|
|
||||||
|
|
||||||
// Find the logs
|
// Find the logs
|
||||||
LogCriteria logCriteria = new LogCriteria()
|
LogCriteria logCriteria = new LogCriteria()
|
||||||
.setMinLevel(Level.toLevel(StringUtils.stripToNull(minLevel)))
|
.setMinLevel(Level.toLevel(StringUtils.stripToNull(minLevel)))
|
||||||
@ -554,7 +545,7 @@ public class AppResource extends BaseResource {
|
|||||||
.setMessage(StringUtils.stripToNull(message));
|
.setMessage(StringUtils.stripToNull(message));
|
||||||
|
|
||||||
PaginatedList<LogEntry> paginatedList = PaginatedLists.create(limit, offset);
|
PaginatedList<LogEntry> paginatedList = PaginatedLists.create(limit, offset);
|
||||||
memoryAppender.find(logCriteria, paginatedList);
|
MemoryAppender.find(logCriteria, paginatedList);
|
||||||
JsonArrayBuilder logs = Json.createArrayBuilder();
|
JsonArrayBuilder logs = Json.createArrayBuilder();
|
||||||
for (LogEntry logEntry : paginatedList.getResultList()) {
|
for (LogEntry logEntry : paginatedList.getResultList()) {
|
||||||
logs.add(Json.createObjectBuilder()
|
logs.add(Json.createObjectBuilder()
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
log4j.rootCategory=WARN, CONSOLE, MEMORY
|
|
||||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %p %l %m %n
|
|
||||||
log4j.appender.MEMORY=com.sismics.util.log4j.MemoryAppender
|
|
||||||
log4j.appender.MEMORY.size=1000
|
|
||||||
|
|
||||||
log4j.logger.com.sismics=INFO
|
|
||||||
log4j.logger.org.apache.pdfbox=ERROR
|
|
||||||
log4j.logger.org.glassfish.jersey.servlet.WebComponent=ERROR
|
|
||||||
log4j.logger.org.apache.directory=ERROR
|
|
||||||
log4j.logger.org.odftoolkit=ERROR
|
|
20
docs-web/src/prod/resources/logback.xml
Normal file
20
docs-web/src/prod/resources/logback.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%date [%t] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
<appender name="MEMORY" class="com.sismics.util.logback.MemoryAppender">
|
||||||
|
<size>1000</size>
|
||||||
|
</appender>
|
||||||
|
<logger name="org.apache.directory" level="ERROR"/>
|
||||||
|
<logger name="com.sismics" level="INFO"/>
|
||||||
|
<logger name="org.apache.pdfbox" level="ERROR"/>
|
||||||
|
<logger name="org.glassfish.jersey.servlet.WebComponent" level="ERROR"/>
|
||||||
|
<logger name="org.odftoolkit" level="ERROR"/>
|
||||||
|
<root level="WARN">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="MEMORY"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
@ -1,15 +0,0 @@
|
|||||||
log4j.rootCategory=INFO, CONSOLE, MEMORY
|
|
||||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %p %l %m %n
|
|
||||||
log4j.appender.MEMORY=com.sismics.util.log4j.MemoryAppender
|
|
||||||
log4j.appender.MEMORY.size=1000
|
|
||||||
|
|
||||||
log4j.logger.com.sismics=INFO
|
|
||||||
log4j.logger.com.sismics.util.jpa=ERROR
|
|
||||||
log4j.logger.org.hibernate=ERROR
|
|
||||||
log4j.logger.org.apache.pdfbox=INFO
|
|
||||||
log4j.logger.com.mchange=ERROR
|
|
||||||
log4j.logger.org.apache.directory=ERROR
|
|
||||||
log4j.logger.org.glassfish.grizzly=ERROR
|
|
||||||
log4j.logger.org.odftoolkit=ERROR
|
|
23
docs-web/src/test/resources/logback.xml
Normal file
23
docs-web/src/test/resources/logback.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%date [%t] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
<appender name="MEMORY" class="com.sismics.util.logback.MemoryAppender">
|
||||||
|
<size>1000</size>
|
||||||
|
</appender>
|
||||||
|
<logger name="org.apache.directory" level="ERROR"/>
|
||||||
|
<logger name="com.sismics" level="INFO"/>
|
||||||
|
<logger name="org.glassfish.grizzly" level="ERROR"/>
|
||||||
|
<logger name="org.apache.pdfbox" level="INFO"/>
|
||||||
|
<logger name="org.hibernate" level="ERROR"/>
|
||||||
|
<logger name="com.mchange" level="ERROR"/>
|
||||||
|
<logger name="com.sismics.util.jpa" level="ERROR"/>
|
||||||
|
<logger name="org.odftoolkit" level="ERROR"/>
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="MEMORY"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
33
pom.xml
33
pom.xml
@ -22,10 +22,11 @@
|
|||||||
<org.apache.commons.commons-email.version>1.5</org.apache.commons.commons-email.version>
|
<org.apache.commons.commons-email.version>1.5</org.apache.commons.commons-email.version>
|
||||||
<org.freemarker.freemarker.version>2.3.32</org.freemarker.freemarker.version>
|
<org.freemarker.freemarker.version>2.3.32</org.freemarker.freemarker.version>
|
||||||
<com.google.guava.guava.version>31.1-jre</com.google.guava.guava.version>
|
<com.google.guava.guava.version>31.1-jre</com.google.guava.guava.version>
|
||||||
<log4j.log4j.version>1.2.17</log4j.log4j.version>
|
<org.slf4j.version>2.0.7</org.slf4j.version>
|
||||||
<org.slf4j.version>1.7.30</org.slf4j.version>
|
<org.slf4j.jcl-over-slf4j.version>2.0.7</org.slf4j.jcl-over-slf4j.version>
|
||||||
<org.slf4j.jcl-over-slf4j.version>1.7.30</org.slf4j.jcl-over-slf4j.version>
|
<org.slf4j.jul-to-slf4j.version>2.0.7</org.slf4j.jul-to-slf4j.version>
|
||||||
<org.slf4j.jul-to-slf4j.version>1.7.30</org.slf4j.jul-to-slf4j.version>
|
<org.apache.logging.log4j.log4j-to-slf4j.version>2.20.0</org.apache.logging.log4j.log4j-to-slf4j.version>
|
||||||
|
<ch.qos.logback.logback-classic.version>1.4.6</ch.qos.logback.logback-classic.version>
|
||||||
<junit.junit.version>4.13.2</junit.junit.version>
|
<junit.junit.version>4.13.2</junit.junit.version>
|
||||||
<com.h2database.h2.version>1.4.199</com.h2database.h2.version>
|
<com.h2database.h2.version>1.4.199</com.h2database.h2.version>
|
||||||
<jakarta.json.jakarta.json-api.version>2.1.1</jakarta.json.jakarta.json-api.version>
|
<jakarta.json.jakarta.json-api.version>2.1.1</jakarta.json.jakarta.json-api.version>
|
||||||
@ -217,18 +218,6 @@
|
|||||||
<version>${com.squareup.okhttp3.okhttp.version}</version>
|
<version>${com.squareup.okhttp3.okhttp.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<version>${log4j.log4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
@ -247,6 +236,18 @@
|
|||||||
<version>${org.slf4j.jul-to-slf4j.version}</version>
|
<version>${org.slf4j.jul-to-slf4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-to-slf4j</artifactId>
|
||||||
|
<version>${org.apache.logging.log4j.log4j-to-slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${ch.qos.logback.logback-classic.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
Loading…
Reference in New Issue
Block a user