Skip to content

Commit

Permalink
removed unused session method and loggers method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Feb 6, 2023
1 parent 461de93 commit 6082f4d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 104 deletions.
9 changes: 0 additions & 9 deletions arc-web/src/main/java/fr/insee/arc/web/util/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,8 @@ public void put(String attributeName, Object attributeValue) {
httpSession.setAttribute(attributeName, attributeValue);
}


public void remove(String attributeName) {
httpSession.removeAttribute(attributeName);
}

public Map<String,Object> asMap(){
Map<String,Object> map = new HashMap<>();

Collections.list(httpSession.getAttributeNames()).forEach(name -> map.put(name, httpSession.getAttribute(name)));

return map;
}

}
126 changes: 31 additions & 95 deletions arc-web/src/main/java/fr/insee/arc/web/util/WebLoggerDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

import fr.insee.arc.core.util.LoggerDispatcher;

/** An implementation of LoggerDispatcher that store the log in the session
* to provide feedback to the user.*/
/**
* An implementation of LoggerDispatcher that store the log in the session to
* provide feedback to the user.
*/
public class WebLoggerDispatcher implements LoggerDispatcher {

@Autowired
private Session session;

/**
* Log and store the message in session.
Expand All @@ -19,33 +18,21 @@ public class WebLoggerDispatcher implements LoggerDispatcher {
* @param logger
*/
public void error(Object message, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isErrorEnabled()) {
logger.error(sanitize(message));
}
if (logger.isErrorEnabled()) {
logger.error(sanitize(message));
}
}

/**
* Log and store the message in session.
*
* @param message
* @param ex an exception to log
* @param ex an exception to log
* @param logger
*/
public void error(Object message, Exception ex, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isErrorEnabled()) {
logger.error(sanitize(message), ex);
}
if (logger.isErrorEnabled()) {
logger.error(sanitize(message), ex);
}
}

Expand All @@ -56,33 +43,21 @@ public void error(Object message, Exception ex, Logger logger) {
* @param logger
*/
public void warn(Object message, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isWarnEnabled()) {
logger.warn(sanitize(message));
}
if (logger.isWarnEnabled()) {
logger.warn(sanitize(message));
}
}

/**
* Log and store the message in session.
*
* @param message
* @param ex an exception to log
* @param ex an exception to log
* @param logger
*/
public void warn(Object message, Exception ex, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isWarnEnabled()) {
logger.warn(sanitize(message), ex);
}
if (logger.isWarnEnabled()) {
logger.warn(sanitize(message), ex);
}
}

Expand All @@ -93,33 +68,21 @@ public void warn(Object message, Exception ex, Logger logger) {
* @param logger
*/
public void info(Object message, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isInfoEnabled()) {
logger.info(sanitize(message));
}
if (logger.isInfoEnabled()) {
logger.info(sanitize(message));
}
}

/**
* Log and store the message in session.
*
* @param message
* @param ex an exception to log
* @param ex an exception to log
* @param logger
*/
public void info(Object message, Exception ex, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isInfoEnabled()) {
logger.info(sanitize(message), ex);
}
if (logger.isInfoEnabled()) {
logger.info(sanitize(message), ex);
}
}

Expand All @@ -130,34 +93,23 @@ public void info(Object message, Exception ex, Logger logger) {
* @param logger
*/
public void debug(Object message, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isDebugEnabled()) {
logger.debug(sanitize(message));
}
if (logger.isDebugEnabled()) {
logger.debug(sanitize(message));
}
}

/**
* Log and store the message in session.
*
* @param message
* @param ex an exception to log
* @param ex an exception to log
* @param logger
*/
public void debug(Object message, Exception ex, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isDebugEnabled()) {
logger.debug(sanitize(message), ex);
}
}
if (logger.isDebugEnabled()) {
logger.debug(sanitize(message), ex);
}

}

/**
Expand All @@ -167,38 +119,22 @@ public void debug(Object message, Exception ex, Logger logger) {
* @param logger
*/
public void trace(Object message, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isTraceEnabled()) {
logger.trace(sanitize(message));
}
if (logger.isTraceEnabled()) {
logger.trace(sanitize(message));
}
}

/**
* Log and store the message in session.
*
* @param message
* @param ex an exception to log
* @param ex an exception to log
* @param logger
*/
public void trace(Object message, Exception ex, Logger logger) {
try {
registerMessage(message);
} catch (Exception e) {
logger.error("An error occured while storing a message in session", e);
} finally {
if (logger.isTraceEnabled()) {
logger.trace(sanitize(message), ex);
}
if (logger.isTraceEnabled()) {
logger.trace(sanitize(message), ex);
}
}

private void registerMessage(Object message) {
session.put("console", (String) session.get("console") + new java.util.Date() + " - "
+ message + "\n");
}
}

0 comments on commit 6082f4d

Please sign in to comment.